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