github.com/alibaba/sealer@v0.8.6-0.20220430115802-37a2bdaa8173/types/api/v1/cluster_types.go (about)

     1  // Copyright © 2021 Alibaba Group Holding Ltd.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package v1
    16  
    17  import (
    18  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    19  )
    20  
    21  type SSH struct {
    22  	Encrypted bool   `json:"encrypted,omitempty"`
    23  	User      string `json:"user,omitempty"`
    24  	Passwd    string `json:"passwd,omitempty"`
    25  	Pk        string `json:"pk,omitempty"`
    26  	PkPasswd  string `json:"pkPasswd,omitempty"`
    27  	Port      string `json:"port,omitempty"`
    28  }
    29  
    30  type Network struct {
    31  	PodCIDR string `json:"podCIDR,omitempty"`
    32  	SvcCIDR string `json:"svcCIDR,omitempty"`
    33  }
    34  
    35  type Hosts struct {
    36  	CPU        string   `json:"cpu,omitempty"`
    37  	Memory     string   `json:"memory,omitempty"`
    38  	Count      string   `json:"count,omitempty"`
    39  	SystemDisk string   `json:"systemDisk,omitempty"`
    40  	DataDisks  []string `json:"dataDisks,omitempty"`
    41  	IPList     []string `json:"ipList,omitempty"`
    42  }
    43  
    44  // EDIT THIS FILE!  THIS IS SCAFFOLDING FOR YOU TO OWN!
    45  // NOTE: json tags are required.  Any new fields you add must have json tags for the fields to be serialized.
    46  
    47  // ClusterSpec defines the desired state of Cluster
    48  type ClusterSpec struct {
    49  	// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
    50  	// Important: Run "make" to regenerate code after modifying this file
    51  
    52  	// Foo is an example field of Cluster. Edit Cluster_types.go to remove/update
    53  	Image    string   `json:"image,omitempty"`
    54  	Env      []string `json:"env,omitempty"`
    55  	Provider string   `json:"provider,omitempty"`
    56  	SSH      SSH      `json:"ssh,omitempty"`
    57  	Network  Network  `json:"network,omitempty"`
    58  	CertSANS []string `json:"certSANS,omitempty"`
    59  	Masters  Hosts    `json:"masters,omitempty"`
    60  	Nodes    Hosts    `json:"nodes,omitempty"`
    61  }
    62  
    63  // ClusterStatus defines the observed state of Cluster
    64  type ClusterStatus struct {
    65  	// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
    66  	// Important: Run "make" to regenerate code after modifying this file
    67  	// TODO save cluster status info
    68  
    69  }
    70  
    71  // +kubebuilder:object:root=true
    72  // +kubebuilder:subresource:status
    73  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
    74  
    75  // Cluster is the Schema for the clusters API
    76  type Cluster struct {
    77  	metav1.TypeMeta   `json:",inline"`
    78  	metav1.ObjectMeta `json:"metadata,omitempty"`
    79  
    80  	Spec   ClusterSpec   `json:"spec,omitempty"`
    81  	Status ClusterStatus `json:"status,omitempty"`
    82  }
    83  
    84  //func (cluster *Cluster) GetClusterEIP() string {
    85  //	return cluster.Annotations[common.Eip]
    86  //}
    87  //
    88  //func (cluster *Cluster) GetClusterMaster0IP() string {
    89  //	return cluster.Annotations[common.Master0InternalIP]
    90  //}
    91  //
    92  //func (cluster *Cluster) GetEipID() string {
    93  //	return cluster.Annotations[common.EipID]
    94  //}
    95  //
    96  //func (cluster *Cluster) GetMaster0ID() string {
    97  //	return cluster.Annotations[common.Master0ID]
    98  //}
    99  //
   100  //func (cluster *Cluster) GetVpcID() string {
   101  //	return cluster.Annotations[common.VpcID]
   102  //}
   103  //
   104  //func (cluster *Cluster) GetVSwitchID() string {
   105  //	return cluster.Annotations[common.VSwitchID]
   106  //}
   107  
   108  func (in *Cluster) GetAnnotationsByKey(key string) string {
   109  	return in.Annotations[key]
   110  }
   111  
   112  func (in *Cluster) SetAnnotations(key, value string) {
   113  	if in.Annotations == nil {
   114  		in.Annotations = make(map[string]string)
   115  	}
   116  	in.Annotations[key] = value
   117  }
   118  
   119  // +kubebuilder:object:root=true
   120  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
   121  
   122  // ClusterList contains a list of Cluster
   123  type ClusterList struct {
   124  	metav1.TypeMeta `json:",inline"`
   125  	metav1.ListMeta `json:"metadata,omitempty"`
   126  	Items           []Cluster `json:"items"`
   127  }
   128  
   129  func init() {
   130  	SchemeBuilder.Register(&Cluster{}, &ClusterList{})
   131  }