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