github.com/deemoprobe/k8s-first-commit@v0.0.0-20230430165612-a541f1982be3/pkg/api/types.go (about) 1 /* 2 Copyright 2014 Google Inc. All rights reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 // Package api includes all types used to communicate between the various 18 // parts of the Kubernetes system. 19 package api 20 21 // ContainerManifest corresponds to the Container Manifest format, documented at: 22 // https://developers.google.com/compute/docs/containers#container_manifest 23 // This is used as the representation of Kubernete's workloads. 24 type ContainerManifest struct { 25 Version string `yaml:"version" json:"version"` 26 Volumes []Volume `yaml:"volumes" json:"volumes"` 27 Containers []Container `yaml:"containers" json:"containers"` 28 Id string `yaml:"id,omitempty" json:"id,omitempty"` 29 } 30 31 type Volume struct { 32 Name string `yaml:"name" json:"name"` 33 } 34 35 type Port struct { 36 Name string `yaml:"name,omitempty" json:"name,omitempty"` 37 HostPort int `yaml:"hostPort,omitempty" json:"hostPort,omitempty"` 38 ContainerPort int `yaml:"containerPort,omitempty" json:"containerPort,omitempty"` 39 Protocol string `yaml:"protocol,omitempty" json:"protocol,omitempty"` 40 } 41 42 type VolumeMount struct { 43 Name string `yaml:"name,omitempty" json:"name,omitempty"` 44 ReadOnly bool `yaml:"readOnly,omitempty" json:"readOnly,omitempty"` 45 MountPath string `yaml:"mountPath,omitempty" json:"mountPath,omitempty"` 46 } 47 48 type EnvVar struct { 49 Name string `yaml:"name,omitempty" json:"name,omitempty"` 50 Value string `yaml:"value,omitempty" json:"value,omitempty"` 51 } 52 53 // Container represents a single container that is expected to be run on the host. 54 type Container struct { 55 Name string `yaml:"name,omitempty" json:"name,omitempty"` 56 Image string `yaml:"image,omitempty" json:"image,omitempty"` 57 Command string `yaml:"command,omitempty" json:"command,omitempty"` 58 WorkingDir string `yaml:"workingDir,omitempty" json:"workingDir,omitempty"` 59 Ports []Port `yaml:"ports,omitempty" json:"ports,omitempty"` 60 Env []EnvVar `yaml:"env,omitempty" json:"env,omitempty"` 61 Memory int `yaml:"memory,omitempty" json:"memory,omitempty"` 62 CPU int `yaml:"cpu,omitempty" json:"cpu,omitempty"` 63 VolumeMounts []VolumeMount `yaml:"volumeMounts,omitempty" json:"volumeMounts,omitempty"` 64 } 65 66 // Event is the representation of an event logged to etcd backends 67 type Event struct { 68 Event string `json:"event,omitempty"` 69 Manifest *ContainerManifest `json:"manifest,omitempty"` 70 Container *Container `json:"container,omitempty"` 71 Timestamp int64 `json:"timestamp"` 72 } 73 74 // The below types are used by kube_client and api_server. 75 76 // JSONBase is shared by all objects sent to, or returned from the client 77 type JSONBase struct { 78 Kind string `json:"kind,omitempty" yaml:"kind,omitempty"` 79 ID string `json:"id,omitempty" yaml:"id,omitempty"` 80 CreationTimestamp string `json:"creationTimestamp,omitempty" yaml:"creationTimestamp,omitempty"` 81 SelfLink string `json:"selfLink,omitempty" yaml:"selfLink,omitempty"` 82 } 83 84 // TaskState is the state of a task, used as either input (desired state) or output (current state) 85 type TaskState struct { 86 Manifest ContainerManifest `json:"manifest,omitempty" yaml:"manifest,omitempty"` 87 Status string `json:"status,omitempty" yaml:"status,omitempty"` 88 Host string `json:"host,omitempty" yaml:"host,omitempty"` 89 HostIP string `json:"hostIP,omitempty" yaml:"hostIP,omitempty"` 90 Info interface{} `json:"info,omitempty" yaml:"info,omitempty"` 91 } 92 93 type TaskList struct { 94 JSONBase 95 Items []Task `json:"items" yaml:"items,omitempty"` 96 } 97 98 // Task is a single task, used as either input (create, update) or as output (list, get) 99 type Task struct { 100 JSONBase 101 Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"` 102 DesiredState TaskState `json:"desiredState,omitempty" yaml:"desiredState,omitempty"` 103 CurrentState TaskState `json:"currentState,omitempty" yaml:"currentState,omitempty"` 104 } 105 106 // ReplicationControllerState is the state of a replication controller, either input (create, update) or as output (list, get) 107 type ReplicationControllerState struct { 108 Replicas int `json:"replicas" yaml:"replicas"` 109 ReplicasInSet map[string]string `json:"replicasInSet,omitempty" yaml:"replicasInSet,omitempty"` 110 TaskTemplate TaskTemplate `json:"taskTemplate,omitempty" yaml:"taskTemplate,omitempty"` 111 } 112 113 type ReplicationControllerList struct { 114 JSONBase 115 Items []ReplicationController `json:"items,omitempty" yaml:"items,omitempty"` 116 } 117 118 // ReplicationController represents the configuration of a replication controller 119 type ReplicationController struct { 120 JSONBase 121 DesiredState ReplicationControllerState `json:"desiredState,omitempty" yaml:"desiredState,omitempty"` 122 Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"` 123 } 124 125 // TaskTemplate holds the information used for creating tasks 126 type TaskTemplate struct { 127 DesiredState TaskState `json:"desiredState,omitempty" yaml:"desiredState,omitempty"` 128 Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"` 129 } 130 131 // ServiceList holds a list of services 132 type ServiceList struct { 133 Items []Service `json:"items" yaml:"items"` 134 } 135 136 // Defines a service abstraction by a name (for example, mysql) consisting of local port 137 // (for example 3306) that the proxy listens on, and the labels that define the service. 138 type Service struct { 139 JSONBase 140 Port int `json:"port,omitempty" yaml:"port,omitempty"` 141 Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"` 142 } 143 144 // Defines the endpoints that implement the actual service, for example: 145 // Name: "mysql", Endpoints: ["10.10.1.1:1909", "10.10.2.2:8834"] 146 type Endpoints struct { 147 Name string 148 Endpoints []string 149 }