github.com/docker/compose-on-kubernetes@v0.5.0/api/compose/v1alpha3/stack.go (about) 1 package v1alpha3 2 3 import ( 4 "time" 5 6 "k8s.io/api/core/v1" 7 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 8 "k8s.io/apimachinery/pkg/runtime" 9 ) 10 11 // StackList is a list of stacks 12 type StackList struct { 13 metav1.TypeMeta `json:",inline"` 14 metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` 15 16 Items []Stack `json:"items" protobuf:"bytes,2,rep,name=items"` 17 } 18 19 // Stack is v1alpha3's representation of a Stack 20 type Stack struct { 21 metav1.TypeMeta `json:",inline"` 22 metav1.ObjectMeta `json:"metadata,omitempty"` 23 24 Spec *StackSpec `json:"spec,omitempty"` 25 Status *StackStatus `json:"status,omitempty"` 26 } 27 28 // DeepCopyObject clones the stack 29 func (s *Stack) DeepCopyObject() runtime.Object { 30 return s.clone() 31 } 32 33 // DeepCopyObject clones the stack list 34 func (s *StackList) DeepCopyObject() runtime.Object { 35 if s == nil { 36 return nil 37 } 38 result := new(StackList) 39 result.TypeMeta = s.TypeMeta 40 result.ListMeta = s.ListMeta 41 if s.Items == nil { 42 return result 43 } 44 result.Items = make([]Stack, len(s.Items)) 45 for ix, s := range s.Items { 46 result.Items[ix] = *s.clone() 47 } 48 return result 49 } 50 51 func (s *Stack) clone() *Stack { 52 if s == nil { 53 return nil 54 } 55 result := new(Stack) 56 result.TypeMeta = s.TypeMeta 57 result.ObjectMeta = s.ObjectMeta 58 result.Spec = s.Spec.DeepCopy() 59 result.Status = s.Status.clone() 60 return result 61 } 62 63 // StackSpec defines the desired state of Stack 64 // +k8s:deepcopy-gen=true 65 type StackSpec struct { 66 Services []ServiceConfig `json:"services,omitempty"` 67 Secrets map[string]SecretConfig `json:"secrets,omitempty"` 68 Configs map[string]ConfigObjConfig `json:"configs,omitempty"` 69 } 70 71 // ServiceConfig is the configuration of one service 72 // +k8s:deepcopy-gen=true 73 type ServiceConfig struct { 74 Name string `json:"name,omitempty"` 75 76 CapAdd []string `json:"cap_add,omitempty"` 77 CapDrop []string `json:"cap_drop,omitempty"` 78 Command []string `json:"command,omitempty"` 79 Configs []ServiceConfigObjConfig `json:"configs,omitempty"` 80 Deploy DeployConfig `json:"deploy,omitempty"` 81 Entrypoint []string `json:"entrypoint,omitempty"` 82 Environment map[string]*string `json:"environment,omitempty"` 83 ExtraHosts []string `json:"extra_hosts,omitempty"` 84 Hostname string `json:"hostname,omitempty"` 85 HealthCheck *HealthCheckConfig `json:"health_check,omitempty"` 86 Image string `json:"image,omitempty"` 87 Ipc string `json:"ipc,omitempty"` 88 Labels map[string]string `json:"labels,omitempty"` 89 Pid string `json:"pid,omitempty"` 90 Ports []ServicePortConfig `json:"ports,omitempty"` 91 Privileged bool `json:"privileged,omitempty"` 92 ReadOnly bool `json:"read_only,omitempty"` 93 Secrets []ServiceSecretConfig `json:"secrets,omitempty"` 94 StdinOpen bool `json:"stdin_open,omitempty"` 95 StopGracePeriod *time.Duration `json:"stop_grace_period,omitempty"` 96 Tmpfs []string `json:"tmpfs,omitempty"` 97 Tty bool `json:"tty,omitempty"` 98 User *int64 `json:"user,omitempty"` 99 Volumes []ServiceVolumeConfig `json:"volumes,omitempty"` 100 WorkingDir string `json:"working_dir,omitempty"` 101 PullSecret string `json:"pull_secret,omitempty"` 102 PullPolicy string `json:"pull_policy,omitempty"` 103 InternalPorts []InternalPort `json:"internal_ports,omitempty"` 104 InternalServiceType InternalServiceType `json:"internal_service_type,omitempty"` 105 } 106 107 // InternalServiceType defines the strategy for defining the Service Type to use for inter-service networking 108 type InternalServiceType string 109 110 const ( 111 // InternalServiceTypeAuto behavior is the same as InternalServiceTypeHeadless if InternalPorts is empty, InternalServiceTypeClusterIP otherwise 112 InternalServiceTypeAuto = InternalServiceType("") 113 // InternalServiceTypeHeadless always create a Headless service 114 InternalServiceTypeHeadless = InternalServiceType("Headless") 115 // InternalServiceTypeClusterIP always create a ClusterIP service 116 InternalServiceTypeClusterIP = InternalServiceType("ClusterIP") 117 ) 118 119 // ServicePortConfig is the port configuration for a service 120 // +k8s:deepcopy-gen=true 121 type ServicePortConfig struct { 122 Mode string `json:"mode,omitempty"` 123 Target uint32 `json:"target,omitempty"` 124 Published uint32 `json:"published,omitempty"` 125 Protocol string `json:"protocol,omitempty"` 126 } 127 128 // FileObjectConfig is a config type for a file used by a service 129 // +k8s:deepcopy-gen=true 130 type FileObjectConfig struct { 131 Name string `json:"name,omitempty"` 132 File string `json:"file,omitempty"` 133 External External `json:"external,omitempty"` 134 Labels map[string]string `json:"labels,omitempty"` 135 } 136 137 // SecretConfig for a secret 138 // +k8s:deepcopy-gen=true 139 type SecretConfig FileObjectConfig 140 141 // ConfigObjConfig is the config for the swarm "Config" object 142 // +k8s:deepcopy-gen=true 143 type ConfigObjConfig FileObjectConfig 144 145 // External identifies a Volume or Network as a reference to a resource that is 146 // not managed, and should already exist. 147 // External.name is deprecated and replaced by Volume.name 148 // +k8s:deepcopy-gen=true 149 type External struct { 150 Name string `json:"name,omitempty"` 151 External bool `json:"external,omitempty"` 152 } 153 154 // FileReferenceConfig for a reference to a swarm file object 155 // +k8s:deepcopy-gen=true 156 type FileReferenceConfig struct { 157 Source string `json:"source,omitempty"` 158 Target string `json:"target,omitempty"` 159 UID string `json:"uid,omitempty"` 160 GID string `json:"gid,omitempty"` 161 Mode *uint32 `json:"mode,omitempty"` 162 } 163 164 // ServiceConfigObjConfig is the config obj configuration for a service 165 // +k8s:deepcopy-gen=true 166 type ServiceConfigObjConfig FileReferenceConfig 167 168 // ServiceSecretConfig is the secret configuration for a service 169 // +k8s:deepcopy-gen=true 170 type ServiceSecretConfig FileReferenceConfig 171 172 // DeployConfig is the deployment configuration for a service 173 // +k8s:deepcopy-gen=true 174 type DeployConfig struct { 175 Mode string `json:"mode,omitempty"` 176 Replicas *uint64 `json:"replicas,omitempty"` 177 Labels map[string]string `json:"labels,omitempty"` 178 UpdateConfig *UpdateConfig `json:"update_config,omitempty"` 179 Resources Resources `json:"resources,omitempty"` 180 RestartPolicy *RestartPolicy `json:"restart_policy,omitempty"` 181 Placement Placement `json:"placement,omitempty"` 182 } 183 184 // UpdateConfig is the service update configuration 185 // +k8s:deepcopy-gen=true 186 type UpdateConfig struct { 187 Parallelism *uint64 `json:"paralellism,omitempty"` 188 } 189 190 // Resources the resource limits and reservations 191 // +k8s:deepcopy-gen=true 192 type Resources struct { 193 Limits *Resource `json:"limits,omitempty"` 194 Reservations *Resource `json:"reservations,omitempty"` 195 } 196 197 // Resource is a resource to be limited or reserved 198 // +k8s:deepcopy-gen=true 199 type Resource struct { 200 NanoCPUs string `json:"cpus,omitempty"` 201 MemoryBytes int64 `json:"memory,omitempty"` 202 } 203 204 // RestartPolicy is the service restart policy 205 // +k8s:deepcopy-gen=true 206 type RestartPolicy struct { 207 Condition string `json:"condition,omitempty"` 208 } 209 210 // Placement constraints for the service 211 // +k8s:deepcopy-gen=true 212 type Placement struct { 213 Constraints *Constraints `json:"constraints,omitempty"` 214 } 215 216 // Constraints lists constraints that can be set on the service 217 // +k8s:deepcopy-gen=true 218 type Constraints struct { 219 OperatingSystem *Constraint 220 Architecture *Constraint 221 Hostname *Constraint 222 MatchLabels map[string]Constraint 223 } 224 225 // Constraint defines a constraint and it's operator (== or !=) 226 // +k8s:deepcopy-gen=true 227 type Constraint struct { 228 Value string 229 Operator string 230 } 231 232 // HealthCheckConfig the healthcheck configuration for a service 233 // +k8s:deepcopy-gen=true 234 type HealthCheckConfig struct { 235 Test []string `json:"test,omitempty"` 236 Timeout *time.Duration `json:"timeout,omitempty"` 237 Interval *time.Duration `json:"interval,omitempty"` 238 Retries *uint64 `json:"retries,omitempty"` 239 } 240 241 // ServiceVolumeConfig are references to a volume used by a service 242 // +k8s:deepcopy-gen=true 243 type ServiceVolumeConfig struct { 244 Type string `json:"type,omitempty"` 245 Source string `json:"source,omitempty"` 246 Target string `json:"target,omitempty"` 247 ReadOnly bool `json:"read_only,omitempty"` 248 } 249 250 // StackPhase is the deployment phase of a stack 251 type StackPhase string 252 253 // These are valid conditions of a stack. 254 const ( 255 // StackAvailable means the stack is available. 256 StackAvailable StackPhase = "Available" 257 // StackProgressing means the deployment is progressing. 258 StackProgressing StackPhase = "Progressing" 259 // StackFailure is added in a stack when one of its members fails to be created 260 // or deleted. 261 StackFailure StackPhase = "Failure" 262 // StackReconciliationPending means the stack has not yet been reconciled 263 StackReconciliationPending StackPhase = "ReconciliationPending" 264 ) 265 266 // StackStatus defines the observed state of Stack 267 type StackStatus struct { 268 // Current condition of the stack. 269 // +optional 270 Phase StackPhase `json:"phase,omitempty" protobuf:"bytes,1,opt,name=phase,casttype=StackPhase"` 271 // A human readable message indicating details about the stack. 272 // +optional 273 Message string `json:"message,omitempty" protobuf:"bytes,5,opt,name=message"` 274 } 275 276 func (s *StackStatus) clone() *StackStatus { 277 if s == nil { 278 return nil 279 } 280 result := *s 281 return &result 282 } 283 284 // Clone clones a Stack 285 func (s *Stack) Clone() *Stack { 286 return s.clone() 287 } 288 289 // InternalPort describes a Port exposed internally to other services 290 // in the stack 291 // +k8s:deepcopy-gen=true 292 type InternalPort struct { 293 Port int32 `json:"port,omitempty"` 294 Protocol v1.Protocol `json:"protocol,omitempty"` 295 }