github.com/sealerio/sealer@v0.11.1-0.20240507115618-f4f89c5853ae/pkg/runtime/k0s/v1beta1/types.go (about)

     1  /*
     2  Copyright 2022 k0s authors
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8  	http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package v1beta1
    18  
    19  import (
    20  	"encoding/json"
    21  	"time"
    22  
    23  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    24  )
    25  
    26  // ClusterSpec defines the desired state of ClusterConfig
    27  type ClusterSpec struct {
    28  	API               *APISpec               `json:"api"`
    29  	ControllerManager *ControllerManagerSpec `json:"controllerManager,omitempty"`
    30  	Scheduler         *SchedulerSpec         `json:"scheduler,omitempty"`
    31  	Storage           *StorageSpec           `json:"storage"`
    32  	Network           *Network               `json:"network"`
    33  	PodSecurityPolicy *PodSecurityPolicy     `json:"podSecurityPolicy"`
    34  	WorkerProfiles    WorkerProfiles         `json:"workerProfiles,omitempty"`
    35  	Telemetry         *ClusterTelemetry      `json:"telemetry"`
    36  	Install           *InstallSpec           `json:"installConfig,omitempty"`
    37  	Images            *ClusterImages         `json:"images"`
    38  	Extensions        *ClusterExtensions     `json:"extensions,omitempty"`
    39  	Konnectivity      *KonnectivitySpec      `json:"konnectivity,omitempty"`
    40  }
    41  
    42  // ClusterConfigStatus defines the observed state of ClusterConfig
    43  type ClusterConfigStatus struct {
    44  	// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
    45  	// Important: Run "make" to regenerate code after modifying this file
    46  }
    47  
    48  //+kubebuilder:object:root=true
    49  //+kubebuilder:subresource:status
    50  //+kubebuilder:validation:Optional
    51  // +genclient
    52  // +genclient:onlyVerbs=create,delete,list,get,watch,update
    53  // +groupName=k0s.k0sproject.io
    54  
    55  // ClusterConfig is the Schema for the clusterconfigs API
    56  type ClusterConfig struct {
    57  	metav1.ObjectMeta `json:"metadata,omitempty"`
    58  	metav1.TypeMeta   `json:",omitempty,inline"`
    59  
    60  	Spec   *ClusterSpec        `json:"spec,omitempty"`
    61  	Status ClusterConfigStatus `json:"status,omitempty"`
    62  }
    63  
    64  // APISpec defines the settings for the K0s API
    65  type APISpec struct {
    66  	// Local address on which to bind an API
    67  	Address string `json:"address"`
    68  
    69  	// The loadbalancer address (for k0s controllers running behind a loadbalancer)
    70  	ExternalAddress string `json:"externalAddress,omitempty"`
    71  	// TunneledNetworkingMode indicates if we access to KAS through konnectivity tunnel
    72  	TunneledNetworkingMode bool `json:"tunneledNetworkingMode"`
    73  	// Map of key-values (strings) for any extra arguments to pass down to Kubernetes api-server process
    74  	ExtraArgs map[string]string `json:"extraArgs,omitempty"`
    75  	// Custom port for k0s-api server to listen on (default: 9443)
    76  	K0sAPIPort int `json:"k0sApiPort,omitempty"`
    77  
    78  	// Custom port for kube-api server to listen on (default: 6443)
    79  	Port int `json:"port"`
    80  
    81  	// List of additional addresses to push to API servers serving the certificate
    82  	SANs []string `json:"sans"`
    83  }
    84  
    85  // ControllerManagerSpec defines the fields for the ControllerManager
    86  type ControllerManagerSpec struct {
    87  	// Map of key-values (strings) for any extra arguments you want to pass down to the Kubernetes controller manager process
    88  	ExtraArgs map[string]string `json:"extraArgs,omitempty"`
    89  }
    90  
    91  // SchedulerSpec defines the fields for the Scheduler
    92  type SchedulerSpec struct {
    93  	// Map of key-values (strings) for any extra arguments you want to pass down to Kubernetes scheduler process
    94  	ExtraArgs map[string]string `json:"extraArgs,omitempty"`
    95  }
    96  
    97  // StorageSpec defines the storage related config options
    98  type StorageSpec struct {
    99  	Etcd *EtcdConfig `json:"etcd"`
   100  	Kine *KineConfig `json:"kine,omitempty"`
   101  
   102  	// Type of the data store (valid values:etcd or kine)
   103  	Type string `json:"type"`
   104  }
   105  
   106  // EtcdConfig defines etcd related config options
   107  type EtcdConfig struct {
   108  	// ExternalCluster defines external etcd cluster related config options
   109  	ExternalCluster *ExternalCluster `json:"externalCluster"`
   110  
   111  	// Node address used for etcd cluster peering
   112  	PeerAddress string `json:"peerAddress"`
   113  }
   114  
   115  // ExternalCluster defines external etcd cluster related config options
   116  type ExternalCluster struct {
   117  	// Endpoints of external etcd cluster used to connect by k0s
   118  	Endpoints []string `json:"endpoints"`
   119  
   120  	// EtcdPrefix is a prefix to prepend to all resource paths in etcd
   121  	EtcdPrefix string `json:"etcdPrefix"`
   122  
   123  	// CaFile is the host path to a file with CA certificate
   124  	CaFile string `json:"caFile"`
   125  
   126  	// ClientCertFile is the host path to a file with TLS certificate for etcd client
   127  	ClientCertFile string `json:"clientCertFile"`
   128  
   129  	// ClientKeyFile is the host path to a file with TLS key for etcd client
   130  	ClientKeyFile string `json:"clientKeyFile"`
   131  }
   132  
   133  // KineConfig defines the Kine related config options
   134  type KineConfig struct {
   135  	// kine datasource URL
   136  	DataSource string `json:"dataSource"`
   137  }
   138  
   139  // Network defines the network related config options
   140  type Network struct {
   141  	Calico     *Calico     `json:"calico"`
   142  	DualStack  DualStack   `json:"dualStack,omitempty"`
   143  	KubeProxy  *KubeProxy  `json:"kubeProxy"`
   144  	KubeRouter *KubeRouter `json:"kuberouter"`
   145  
   146  	// Pod network CIDR to use in the cluster
   147  	PodCIDR string `json:"podCIDR"`
   148  	// Network provider (valid values: calico, kuberouter, or custom)
   149  	Provider string `json:"provider"`
   150  	// Network CIDR to use for cluster VIP services
   151  	ServiceCIDR string `json:"serviceCIDR,omitempty"`
   152  	// Cluster Domain
   153  	ClusterDomain string `json:"clusterDomain,omitempty"`
   154  }
   155  
   156  // Calico defines the calico related config options
   157  type Calico struct {
   158  	// Enable wireguard-based encryption (default: false)
   159  	EnableWireguard bool `json:"wireguard"`
   160  
   161  	// The host path for Calicos flex-volume-driver(default: /usr/libexec/k0s/kubelet-plugins/volume/exec/nodeagent~uds)
   162  	FlexVolumeDriverPath string `json:"flexVolumeDriverPath"`
   163  
   164  	// Host's IP Auto-detection method for Calico (see https://docs.projectcalico.org/reference/node/configuration#ip-autodetection-methods)
   165  	IPAutodetectionMethod string `json:"ipAutodetectionMethod,omitempty"`
   166  
   167  	// Host's IPv6 Auto-detection method for Calico
   168  	IPv6AutodetectionMethod string `json:"ipV6AutodetectionMethod,omitempty"`
   169  
   170  	// MTU for overlay network (default: 0)
   171  	MTU int `json:"mtu" yaml:"mtu"`
   172  
   173  	// vxlan (default) or ipip
   174  	Mode string `json:"mode"`
   175  
   176  	// Overlay Type (Always, Never or CrossSubnet)
   177  	Overlay string `json:"overlay" validate:"oneof=Always Never CrossSubnet" `
   178  
   179  	// The UDP port for VXLAN (default: 4789)
   180  	VxlanPort int `json:"vxlanPort"`
   181  
   182  	// The virtual network ID for VXLAN (default: 4096)
   183  	VxlanVNI int `json:"vxlanVNI"`
   184  
   185  	// Windows Nodes (default: false)
   186  	WithWindowsNodes bool `json:"withWindowsNodes"`
   187  }
   188  
   189  // DualStack defines network configuration for ipv4\ipv6 mixed cluster setup
   190  type DualStack struct {
   191  	Enabled         bool   `json:"enabled,omitempty"`
   192  	IPv6PodCIDR     string `json:"IPv6podCIDR,omitempty"`
   193  	IPv6ServiceCIDR string `json:"IPv6serviceCIDR,omitempty"`
   194  }
   195  
   196  // KubeProxy defines the configuration for kube-proxy
   197  type KubeProxy struct {
   198  	Disabled bool   `json:"disabled,omitempty"`
   199  	Mode     string `json:"mode,omitempty"`
   200  }
   201  
   202  // KubeRouter defines the kube-router related config options
   203  type KubeRouter struct {
   204  	// Auto-detection of used MTU (default: true)
   205  	AutoMTU bool `json:"autoMTU"`
   206  	// Override MTU setting (autoMTU must be set to false)
   207  	MTU int `json:"mtu"`
   208  	// Comma-separated list of global peer addresses
   209  	PeerRouterASNs string `json:"peerRouterASNs"`
   210  	// Comma-separated list of global peer ASNs
   211  	PeerRouterIPs string `json:"peerRouterIPs"`
   212  }
   213  
   214  // PodSecurityPolicy defines the config options for setting system level default PSP
   215  type PodSecurityPolicy struct {
   216  	// default PSP for the cluster (00-k0s-privileged/99-k0s-restricted)
   217  	DefaultPolicy string `json:"defaultPolicy"`
   218  }
   219  
   220  // WorkerProfiles profiles collection
   221  type WorkerProfiles []WorkerProfile
   222  
   223  // WorkerProfile worker profile
   224  type WorkerProfile struct {
   225  	// String; name to use as profile selector for the worker process
   226  	Name string `json:"name"`
   227  	// Worker Mapping object
   228  	Config json.RawMessage `json:"values"`
   229  }
   230  
   231  // ClusterTelemetry holds telemetry related settings
   232  type ClusterTelemetry struct {
   233  	Enabled bool `json:"enabled"`
   234  }
   235  
   236  // InstallSpec defines the required fields for the `k0s install` command
   237  type InstallSpec struct {
   238  	SystemUsers *SystemUser `json:"users,omitempty"`
   239  }
   240  
   241  // SystemUser defines the user to use for each component
   242  type SystemUser struct {
   243  	Etcd          string `json:"etcdUser,omitempty"`
   244  	Kine          string `json:"kineUser,omitempty"`
   245  	Konnectivity  string `json:"konnectivityUser,omitempty"`
   246  	KubeAPIServer string `json:"kubeAPIserverUser,omitempty"`
   247  	KubeScheduler string `json:"kubeSchedulerUser,omitempty"`
   248  }
   249  
   250  // ClusterImages sets docker images for addon components
   251  type ClusterImages struct {
   252  	Konnectivity  ImageSpec `json:"konnectivity"`
   253  	PushGateway   ImageSpec `json:"pushgateway"`
   254  	MetricsServer ImageSpec `json:"metricsserver"`
   255  	KubeProxy     ImageSpec `json:"kubeproxy"`
   256  	CoreDNS       ImageSpec `json:"coredns"`
   257  
   258  	Calico     CalicoImageSpec     `json:"calico"`
   259  	KubeRouter KubeRouterImageSpec `json:"kuberouter"`
   260  
   261  	Repository        string `json:"repository,omitempty"`
   262  	DefaultPullPolicy string `json:"default_pull_policy,omitempty"`
   263  }
   264  
   265  // ImageSpec container image settings
   266  type ImageSpec struct {
   267  	Image   string `json:"image"`
   268  	Version string `json:"version"`
   269  }
   270  
   271  // CalicoImageSpec config group for calico related image settings
   272  type CalicoImageSpec struct {
   273  	CNI             ImageSpec `json:"cni"`
   274  	Node            ImageSpec `json:"node"`
   275  	KubeControllers ImageSpec `json:"kubecontrollers"`
   276  }
   277  
   278  // KubeRouterImageSpec config group for kube-router related images
   279  type KubeRouterImageSpec struct {
   280  	CNI          ImageSpec `json:"cni"`
   281  	CNIInstaller ImageSpec `json:"cniInstaller"`
   282  }
   283  
   284  // ClusterExtensions specifies cluster extensions
   285  type ClusterExtensions struct {
   286  	Storage *StorageExtension `json:"storage"`
   287  	Helm    *HelmExtensions   `json:"helm"`
   288  }
   289  
   290  // StorageExtension specifies cluster default storage
   291  type StorageExtension struct {
   292  	Type                      string `json:"type"`
   293  	CreateDefaultStorageClass bool   `json:"create_default_storage_class"`
   294  }
   295  
   296  // HelmExtensions specifies settings for cluster helm based extensions
   297  type HelmExtensions struct {
   298  	Repositories RepositoriesSettings `json:"repositories"`
   299  	Charts       ChartsSettings       `json:"charts"`
   300  }
   301  
   302  // RepositoriesSettings repository settings
   303  type RepositoriesSettings []Repository
   304  
   305  // Repository describes single repository entry. Fields map to the CLI flags for the "helm add" command
   306  type Repository struct {
   307  	Name     string `json:"name"`
   308  	URL      string `json:"url"`
   309  	CAFile   string `json:"caFile"`
   310  	CertFile string `json:"certFile"`
   311  	Insecure bool   `json:"insecure"`
   312  	KeyFile  string `json:"keyfile"`
   313  	Username string `json:"username"`
   314  	Password string `json:"password"`
   315  }
   316  
   317  // ChartsSettings charts settings
   318  type ChartsSettings []Chart
   319  
   320  // Chart single helm addon
   321  type Chart struct {
   322  	Name      string        `json:"name"`
   323  	ChartName string        `json:"chartname"`
   324  	Version   string        `json:"version"`
   325  	Values    string        `json:"values"`
   326  	TargetNS  string        `json:"namespace"`
   327  	Timeout   time.Duration `json:"timeout"`
   328  }
   329  
   330  // KonnectivitySpec defines the requested state for Konnectivity
   331  type KonnectivitySpec struct {
   332  	// agent port to listen on (default 8132)
   333  	AgentPort int64 `json:"agentPort,omitempty"`
   334  	// admin port to listen on (default 8133)
   335  	AdminPort int64 `json:"adminPort,omitempty"`
   336  }