github.com/AliyunContainerService/cli@v0.0.0-20181009023821-814ced4b30d0/kubernetes/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.clone()
    58  	result.Status = s.Status.clone()
    59  	return result
    60  }
    61  
    62  // StackSpec defines the desired state of Stack
    63  type StackSpec struct {
    64  	Services []ServiceConfig            `json:"services,omitempty"`
    65  	Secrets  map[string]SecretConfig    `json:"secrets,omitempty"`
    66  	Configs  map[string]ConfigObjConfig `json:"configs,omitempty"`
    67  }
    68  
    69  // ServiceConfig is the configuration of one service
    70  type ServiceConfig struct {
    71  	Name string `json:"name,omitempty"`
    72  
    73  	CapAdd          []string                 `json:"cap_add,omitempty"`
    74  	CapDrop         []string                 `json:"cap_drop,omitempty"`
    75  	Command         []string                 `json:"command,omitempty"`
    76  	Configs         []ServiceConfigObjConfig `json:"configs,omitempty"`
    77  	Deploy          DeployConfig             `json:"deploy,omitempty"`
    78  	Entrypoint      []string                 `json:"entrypoint,omitempty"`
    79  	Environment     map[string]*string       `json:"environment,omitempty"`
    80  	ExtraHosts      []string                 `json:"extra_hosts,omitempty"`
    81  	Hostname        string                   `json:"hostname,omitempty"`
    82  	HealthCheck     *HealthCheckConfig       `json:"health_check,omitempty"`
    83  	Image           string                   `json:"image,omitempty"`
    84  	Ipc             string                   `json:"ipc,omitempty"`
    85  	Labels          map[string]string        `json:"labels,omitempty"`
    86  	Pid             string                   `json:"pid,omitempty"`
    87  	Ports           []ServicePortConfig      `json:"ports,omitempty"`
    88  	Privileged      bool                     `json:"privileged,omitempty"`
    89  	ReadOnly        bool                     `json:"read_only,omitempty"`
    90  	Secrets         []ServiceSecretConfig    `json:"secrets,omitempty"`
    91  	StdinOpen       bool                     `json:"stdin_open,omitempty"`
    92  	StopGracePeriod *time.Duration           `json:"stop_grace_period,omitempty"`
    93  	Tmpfs           []string                 `json:"tmpfs,omitempty"`
    94  	Tty             bool                     `json:"tty,omitempty"`
    95  	User            *int64                   `json:"user,omitempty"`
    96  	Volumes         []ServiceVolumeConfig    `json:"volumes,omitempty"`
    97  	WorkingDir      string                   `json:"working_dir,omitempty"`
    98  }
    99  
   100  // ServicePortConfig is the port configuration for a service
   101  type ServicePortConfig struct {
   102  	Mode      string `json:"mode,omitempty"`
   103  	Target    uint32 `json:"target,omitempty"`
   104  	Published uint32 `json:"published,omitempty"`
   105  	Protocol  string `json:"protocol,omitempty"`
   106  }
   107  
   108  // FileObjectConfig is a config type for a file used by a service
   109  type FileObjectConfig struct {
   110  	Name     string            `json:"name,omitempty"`
   111  	File     string            `json:"file,omitempty"`
   112  	External External          `json:"external,omitempty"`
   113  	Labels   map[string]string `json:"labels,omitempty"`
   114  }
   115  
   116  // SecretConfig for a secret
   117  type SecretConfig FileObjectConfig
   118  
   119  // ConfigObjConfig is the config for the swarm "Config" object
   120  type ConfigObjConfig FileObjectConfig
   121  
   122  // External identifies a Volume or Network as a reference to a resource that is
   123  // not managed, and should already exist.
   124  // External.name is deprecated and replaced by Volume.name
   125  type External struct {
   126  	Name     string `json:"name,omitempty"`
   127  	External bool   `json:"external,omitempty"`
   128  }
   129  
   130  // FileReferenceConfig for a reference to a swarm file object
   131  type FileReferenceConfig struct {
   132  	Source string  `json:"source,omitempty"`
   133  	Target string  `json:"target,omitempty"`
   134  	UID    string  `json:"uid,omitempty"`
   135  	GID    string  `json:"gid,omitempty"`
   136  	Mode   *uint32 `json:"mode,omitempty"`
   137  }
   138  
   139  // ServiceConfigObjConfig is the config obj configuration for a service
   140  type ServiceConfigObjConfig FileReferenceConfig
   141  
   142  // ServiceSecretConfig is the secret configuration for a service
   143  type ServiceSecretConfig FileReferenceConfig
   144  
   145  // DeployConfig is the deployment configuration for a service
   146  type DeployConfig struct {
   147  	Mode          string            `json:"mode,omitempty"`
   148  	Replicas      *uint64           `json:"replicas,omitempty"`
   149  	Labels        map[string]string `json:"labels,omitempty"`
   150  	UpdateConfig  *UpdateConfig     `json:"update_config,omitempty"`
   151  	Resources     Resources         `json:"resources,omitempty"`
   152  	RestartPolicy *RestartPolicy    `json:"restart_policy,omitempty"`
   153  	Placement     Placement         `json:"placement,omitempty"`
   154  }
   155  
   156  // UpdateConfig is the service update configuration
   157  type UpdateConfig struct {
   158  	Parallelism *uint64 `json:"paralellism,omitempty"`
   159  }
   160  
   161  // Resources the resource limits and reservations
   162  type Resources struct {
   163  	Limits       *Resource `json:"limits,omitempty"`
   164  	Reservations *Resource `json:"reservations,omitempty"`
   165  }
   166  
   167  // Resource is a resource to be limited or reserved
   168  type Resource struct {
   169  	NanoCPUs    string `json:"cpus,omitempty"`
   170  	MemoryBytes int64  `json:"memory,omitempty"`
   171  }
   172  
   173  // RestartPolicy is the service restart policy
   174  type RestartPolicy struct {
   175  	Condition string `json:"condition,omitempty"`
   176  }
   177  
   178  // Placement constraints for the service
   179  type Placement struct {
   180  	Constraints *Constraints `json:"constraints,omitempty"`
   181  }
   182  
   183  // Constraints lists constraints that can be set on the service
   184  type Constraints struct {
   185  	OperatingSystem *Constraint
   186  	Architecture    *Constraint
   187  	Hostname        *Constraint
   188  	MatchLabels     map[string]Constraint
   189  }
   190  
   191  // Constraint defines a constraint and it's operator (== or !=)
   192  type Constraint struct {
   193  	Value    string
   194  	Operator string
   195  }
   196  
   197  // HealthCheckConfig the healthcheck configuration for a service
   198  type HealthCheckConfig struct {
   199  	Test     []string       `json:"test,omitempty"`
   200  	Timeout  *time.Duration `json:"timeout,omitempty"`
   201  	Interval *time.Duration `json:"interval,omitempty"`
   202  	Retries  *uint64        `json:"retries,omitempty"`
   203  }
   204  
   205  // ServiceVolumeConfig are references to a volume used by a service
   206  type ServiceVolumeConfig struct {
   207  	Type     string `json:"type,omitempty"`
   208  	Source   string `json:"source,omitempty"`
   209  	Target   string `json:"target,omitempty"`
   210  	ReadOnly bool   `json:"read_only,omitempty"`
   211  }
   212  
   213  func (s *StackSpec) clone() *StackSpec {
   214  	if s == nil {
   215  		return nil
   216  	}
   217  	result := *s
   218  	return &result
   219  }
   220  
   221  // StackPhase is the deployment phase of a stack
   222  type StackPhase string
   223  
   224  // These are valid conditions of a stack.
   225  const (
   226  	// StackAvailable means the stack is available.
   227  	StackAvailable StackPhase = "Available"
   228  	// StackProgressing means the deployment is progressing.
   229  	StackProgressing StackPhase = "Progressing"
   230  	// StackFailure is added in a stack when one of its members fails to be created
   231  	// or deleted.
   232  	StackFailure StackPhase = "Failure"
   233  )
   234  
   235  // StackStatus defines the observed state of Stack
   236  type StackStatus struct {
   237  	// Current condition of the stack.
   238  	// +optional
   239  	Phase StackPhase `json:"phase,omitempty" protobuf:"bytes,1,opt,name=phase,casttype=StackPhase"`
   240  	// A human readable message indicating details about the stack.
   241  	// +optional
   242  	Message string `json:"message,omitempty" protobuf:"bytes,5,opt,name=message"`
   243  }
   244  
   245  func (s *StackStatus) clone() *StackStatus {
   246  	if s == nil {
   247  		return nil
   248  	}
   249  	result := *s
   250  	return &result
   251  }
   252  
   253  // Clone clones a Stack
   254  func (s *Stack) Clone() *Stack {
   255  	return s.clone()
   256  }