// 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";

package adapter.template.kubernetes;

import "mixer/v1/template/extensions.proto";
import "mixer/v1/template/standard_types.proto";

option (istio.mixer.v1.template.template_variety) = TEMPLATE_VARIETY_ATTRIBUTE_GENERATOR;

// kubernetes template represents data used to generate kubernetes attributes.
//
// The values provided controls the manner in which the kubernetesenv adapter discovers and
// generates values related to pod information.
//
// Example config:
// ```
// 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
// ```
message Template {
    // Source pod's uid. Must be of the form: "kubernetes://pod.namespace"
    string source_uid = 1;

    // Source pod's ip.
    istio.mixer.v1.template.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.mixer.v1.template.IPAddress destination_ip = 4;

    // Origin pod's uid. Must be of the form: "kubernetes://pod.namespace"
    string origin_uid = 5;

    // Origin pod's ip.
    istio.mixer.v1.template.IPAddress origin_ip = 6;
}

// 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.
message OutputTemplate {
    // Refers to source pod ip address. attribute_bindings can refer to this field using $out.source_pod_ip
    istio.mixer.v1.template.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 service. attribute_bindings can refer to this field using $out.source_service
    string source_service = 5;

    // 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.mixer.v1.template.IPAddress source_host_ip = 7;



    // Refers to destination pod ip address. attribute_bindings can refer to this field using $out.destination_pod_ip
    istio.mixer.v1.template.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 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 service. attribute_bindings can refer to this field using $out.destination_service
    string destination_service = 12;

    // 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.mixer.v1.template.IPAddress destination_host_ip = 14;



    // Refers to origin pod ip address. attribute_bindings can refer to this field using $out.origin_pod_ip
    istio.mixer.v1.template.IPAddress origin_pod_ip = 15;

    // Refers to origin pod name. attribute_bindings can refer to this field using $out.origin_pod_name
    string origin_pod_name = 16;

    // Refers to origin pod labels. attribute_bindings can refer to this field using $out.origin_labels
    map<string, string> origin_labels = 17;

    // Refers to origin pod namespace. attribute_bindings can refer to this field using $out.origin_namespace
    string origin_namespace = 18;

    // Refers to origin service. attribute_bindings can refer to this field using $out.origin_service
    string origin_service = 19;

    // Refers to origin pod service account name. attribute_bindings can refer to this field using $out.origin_service_account_name
    string origin_service_account_name = 20;

    // Refers to origin pod host ip address. attribute_bindings can refer to this field using $out.origin_host_ip
    istio.mixer.v1.template.IPAddress origin_host_ip = 21;
}
