// Copyright 2017 Istio Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";

// $title: Kubernetes
// $description: A template that is used to control the production of Kubernetes-specific attributes.
// $location: https://istio.io/docs/reference/config/policy-and-telemetry/templates/kubernetes.html

// The `kubernetes` template holds data that controls the production of Kubernetes-specific
// attributes.
//
// Example config:
//
// ```yaml
// apiVersion: "config.istio.io/v1alpha2"
// kind: kubernetes
// metadata:
//   name: attributes
//   namespace: istio-system
// spec:
//   # Pass the required attribute data to the adapter
//   source_uid: source.uid | ""
//   source_ip: source.ip | ip("0.0.0.0") # default to unspecified ip addr
//   destination_uid: destination.uid | ""
//   destination_ip: destination.ip | ip("0.0.0.0") # default to unspecified ip addr
//   attribute_bindings:
//     # Fill the new attributes from the adapter produced output.
//     # $out refers to an instance of OutputTemplate message
//     source.ip: $out.source_pod_ip
//     source.labels: $out.source_labels
//     source.namespace: $out.source_namespace
//     source.service: $out.source_service
//     source.serviceAccount: $out.source_service_account_name
//     destination.ip: $out.destination_pod_ip
//     destination.labels: $out.destination_labels
//     destination.namespace: $out.destination_mamespace
//     destination.service: $out.destination_service
//     destination.serviceAccount: $out.destination_service_account_name
// ```
package adapter.template.kubernetes;

import "mixer/adapter/model/v1beta1/extensions.proto";
import "policy/v1beta1/type.proto";

option (istio.mixer.adapter.model.v1beta1.template_variety) = TEMPLATE_VARIETY_ATTRIBUTE_GENERATOR;

// The `kubernetes` template represents data used to generate kubernetes-derived attributes.
//
// The values provided controls the manner in which the kubernetesenv adapter discovers and
// generates values related to pod information.
// Next ID: 8
message Template {
    reserved 5, 6;
    
    // Source pod's uid. Must be of the form: "kubernetes://pod.namespace"
    string source_uid = 1;

    // Source pod's ip.
    istio.policy.v1beta1.IPAddress source_ip = 2;

    // Destination pod's uid. Must be of the form: "kubernetes://pod.namespace"
    string destination_uid = 3;

    // Destination pod's ip.
    istio.policy.v1beta1.IPAddress destination_ip = 4;

    // Destination container's port number.
    int64 destination_port = 7;
}

// OutputTemplate refers to the output from the adapter. It is used inside the attribute_binding section of the config
// to assign values to the generated attributes using the `$out.<field name of the OutputTemplate>` syntax.
// Next ID: 33
message OutputTemplate {
    reserved 5, 12, 15, 16, 17, 18, 19, 21;

    // Refers to the source.uid for a pod. This is for TCP use cases where the attribute is not present.
    // attribute_bindings can refer to this field using $out.source_pod_uid
    string source_pod_uid = 31;

    // Refers to source pod ip address. attribute_bindings can refer to this field using $out.source_pod_ip
    istio.policy.v1beta1.IPAddress source_pod_ip = 1;

    // Refers to source pod name. attribute_bindings can refer to this field using $out.source_pod_name
    string source_pod_name = 2;

    // Refers to source pod labels. attribute_bindings can refer to this field using $out.source_labels
    map<string, string> source_labels = 3;

    // Refers to source pod namespace. attribute_bindings can refer to this field using $out.source_namespace
    string source_namespace = 4;

    // Refers to source pod service account name. attribute_bindings can refer to this field using $out.source_service_account_name
    string source_service_account_name = 6;

    // Refers to source pod host ip address. attribute_bindings can refer to this field using $out.source_host_ip
    istio.policy.v1beta1.IPAddress source_host_ip = 7;

    // Refers to the Istio workload identifier for the source pod. Attribute_bindings can refer to this field using $out.source_workload_uid
    string source_workload_uid = 22;

    // Refers to the Istio workload name for the source pod. Attribute_bindings can refer to this field using $out.source_workload_name
    string source_workload_name = 23;

    // Refers to the Istio workload namespace for the source pod. Attribute_bindings can refer to this field using $out.source_workload_namespace
    string source_workload_namespace = 24;

    // Refers to the (controlling) owner of the source pod. Attribute_bindings can refer to this field using $out.source_owner
    string source_owner = 25;

    // Refers to the destination.uid for a pod. This is for TCP use cases where the attribute is not present.
    // attribute_bindings can refer to this field using $out.destination_pod_uid
    string destination_pod_uid = 32;

    // Refers to destination pod ip address. attribute_bindings can refer to this field using $out.destination_pod_ip
    istio.policy.v1beta1.IPAddress destination_pod_ip = 8;

    // Refers to destination pod name. attribute_bindings can refer to this field using $out.destination_pod_name
    string destination_pod_name = 9;

    // Refers to destination container name. attribute_bindings can refer to this field using $out.destination_container_name
    string destination_container_name = 30;

    // Refers to destination pod labels. attribute_bindings can refer to this field using $out.destination_labels
    map<string, string> destination_labels = 10;

    // Refers to destination pod namespace. attribute_bindings can refer to this field using $out.destination_namespace
    string destination_namespace = 11;

    // Refers to destination pod service account name. attribute_bindings can refer to this field using $out.destination_service_account_name
    string destination_service_account_name = 13;

    // Refers to destination pod host ip address. attribute_bindings can refer to this field using $out.destination_host_ip
    istio.policy.v1beta1.IPAddress destination_host_ip = 14;

    // Refers to the (controlling) owner of the destination pod. Attribute_bindings can refer to this field using $out.destination_owner
    string destination_owner = 26;

    // Refers to the Istio workload identifier for the destination pod. Attribute_bindings can refer to this field using $out.destination_workload_uid
    string destination_workload_uid = 27;

    // Refers to the Istio workload name for the destination pod. Attribute_bindings can refer to this field using $out.destination_workload_name
    string destination_workload_name = 28;

    // Refers to the Istio workload name for the destination pod. Attribute_bindings can refer to this field using $out.destination_workload_namespace
    string destination_workload_namespace = 29;
}
