syntax = "proto3";

package yandex.cloud.k8s.v1;

import "google/protobuf/timestamp.proto";

import "yandex/cloud/k8s/v1/maintenance.proto";
import "yandex/cloud/k8s/v1/version.proto";
import "yandex/cloud/validation.proto";

option go_package = "github.com/yandex-cloud/go-genproto/yandex/cloud/k8s/v1;k8s";
option java_package = "yandex.cloud.api.k8s.v1";

// A Kubernetes cluster.
message Cluster {
  enum Status {
    STATUS_UNSPECIFIED = 0;

    // Kubernetes cluster is waiting for resources to be allocated.
    PROVISIONING = 1;

    // Kubernetes cluster is running.
    RUNNING = 2;

    // Kubernetes cluster is being reconciled.
    RECONCILING = 3;

    // Kubernetes cluster is being stopped.
    STOPPING = 4;

    // Kubernetes cluster stopped.
    STOPPED = 5;

    // Kubernetes cluster is being deleted.
    DELETING = 6;

    // Kubernetes cluster is being started.
    STARTING = 7;
  }

  enum Health {
    HEALTH_UNSPECIFIED = 0;

    // Kubernetes cluster is alive and well.
    HEALTHY = 1;

    // Kubernetes cluster is inoperable.
    UNHEALTHY = 2;
  }

  // ID of the Kubernetes cluster.
  string id = 1;

  // ID of the folder that the Kubernetes cluster belongs to.
  string folder_id = 2;

  // Creation timestamp.
  google.protobuf.Timestamp created_at = 3;

  // Name of the Kubernetes cluster.
  string name = 4;

  // Description of the Kubernetes cluster. 0-256 characters long.
  string description = 5;

  // Resource labels as `key:value` pairs. Maximum of 64 per resource.
  map<string, string> labels = 6;

  // Status of the Kubernetes cluster.
  Status status = 7;

  // Health of the Kubernetes cluster.
  Health health = 8;

  // ID of the network the Kubernetes cluster belongs to.
  string network_id = 9;

  // Properties of the master for the Kubernetes cluster.
  Master master = 10;

  // Allocation policy for IP addresses of services and pods inside the Kubernetes cluster in different availability zones.
  IPAllocationPolicy ip_allocation_policy = 11;

  oneof internet_gateway {
    // Gateway IPv4 address.
    string gateway_ipv4_address = 12 [(length) = "<=15"];
  }

  // Service account to be used for provisioning Compute Cloud and VPC resources for Kubernetes cluster.
  string service_account_id = 13;

  // Service account to be used by the worker nodes of the Kubernetes cluster to access Container Registry or to push node logs and metrics.
  string node_service_account_id = 14;

  // When creating a Kubernetes cluster, you should specify one of three release channels. The release channel contains several Kubernetes versions.
  // Channels differ in the set of available versions, the management of auto-updates, and the updates received.
  // You can't change the channel once the Kubernetes cluster is created, you can only recreate the Kubernetes cluster and specify a new release channel.
  // For more details see [documentation](https://cloud.yandex.com/docs/managed-kubernetes/concepts/release-channels-and-updates).
  ReleaseChannel release_channel = 15;

  NetworkPolicy network_policy = 16;

  // KMS provider configuration.
  KMSProvider kms_provider = 17;

  // Log group where cluster stores cluster system logs, like audit, events, or controlplane logs.
  string log_group_id = 18;

  oneof network_implementation {
    Cilium cilium = 19;
  }
}

enum ReleaseChannel {
  RELEASE_CHANNEL_UNSPECIFIED = 0;

  // Minor updates with new functions and improvements are often added.
  // You can't disable automatic updates in this channel, but you can specify a time period for automatic updates.
  RAPID = 1;

  // New functions and improvements are added in chunks shortly after they appear on `RAPID`.
  REGULAR = 2;

  // Only updates related to bug fixes or security improvements are added.
  STABLE = 3;
}

message Master {
  oneof master_type {
    // Parameters of the availability zone for the master.
    ZonalMaster zonal_master = 1;

    // Parameters of the region for the master.
    RegionalMaster regional_master = 7;
  }

  // Version of Kubernetes components that runs on the master.
  string version = 2;

  // Endpoints of the master. Endpoints constitute of scheme and port (i.e. `https://ip-address:port`)
  //and can be used by the clients to communicate with the Kubernetes API of the Kubernetes cluster.
  MasterEndpoints endpoints = 3;

  // Master authentication parameters are used to establish trust between the master and a client.
  MasterAuth master_auth = 4;

  // Detailed information about the Kubernetes version that is running on the master.
  VersionInfo version_info = 5;

  // Maintenance policy of the master.
  MasterMaintenancePolicy maintenance_policy = 6;

  // Master security groups.
  repeated string security_group_ids = 8;
}

message MasterAuth {
  // PEM-encoded public certificate that is the root of trust for the Kubernetes cluster.
  string cluster_ca_certificate = 1;
}

message ZonalMaster {
  // ID of the availability zone where the master resides.
  string zone_id = 1;

  // IPv4 internal network address that is assigned to the master.
  string internal_v4_address = 2;

  // IPv4 external network address that is assigned to the master.
  string external_v4_address = 3;
}

message RegionalMaster {
  // ID of the region where the master resides.
  string region_id = 1;

  // IPv4 internal network address that is assigned to the master.
  string internal_v4_address = 2;

  // IPv4 external network address that is assigned to the master.
  string external_v4_address = 3;
}

message MasterEndpoints {
  // Internal endpoint that can be used to connect to the master from cloud networks.
  string internal_v4_endpoint = 1;

  // External endpoint that can be used to access Kubernetes cluster API from the internet (outside of the cloud).
  string external_v4_endpoint = 2;
}

message IPAllocationPolicy {
  // CIDR block. IP range for allocating pod addresses.
  //
  // It should not overlap with any subnet in the network the Kubernetes cluster located in. Static routes will be
  // set up for this CIDR blocks in node subnets.
  string cluster_ipv4_cidr_block = 1;

  // Size of the masks that are assigned for each node in the cluster.
  //
  // If not specified, 24 is used.
  int64 node_ipv4_cidr_mask_size = 5 [(value) = "0,24,25,26,27,28"];

  // CIDR block. IP range Kubernetes service Kubernetes cluster IP addresses will be allocated from.
  //
  // It should not overlap with any subnet in the network the Kubernetes cluster located in.
  string service_ipv4_cidr_block = 2;

  // IPv6 range for allocating pod IP addresses.
  string cluster_ipv6_cidr_block = 6;
  // IPv6 range for allocating Kubernetes service IP addresses
  string service_ipv6_cidr_block = 7;
}

message MasterMaintenancePolicy {
  // If set to true, automatic updates are installed in the specified period of time with no interaction from the user.
  // If set to false, automatic upgrades are disabled.
  bool auto_upgrade = 1;

  // Maintenance window settings. Update will start at the specified time and last no more than the specified duration.
  // The time is set in UTC.
  MaintenanceWindow maintenance_window = 2;
}

message NetworkPolicy {
  enum Provider {
    PROVIDER_UNSPECIFIED = 0;
    CALICO = 1;
  }
  Provider provider = 1;
}

message KMSProvider {
  // KMS key ID for secrets encryption.
  // To obtain a KMS key ID use a [yandex.cloud.kms.v1.SymmetricKeyService.List] request.
  string key_id = 1;
}

message Cilium {
  enum RoutingMode {
    ROUTING_MODE_UNSPECIFIED = 0;
    TUNNEL = 1;
  }

  RoutingMode routing_mode = 1;
}
