From 229e2f77df625fba8e580b35fdfcb2d4f5520ceb Mon Sep 17 00:00:00 2001 From: Tom Wieczorek Date: Thu, 27 Jun 2024 16:31:25 +0200 Subject: [PATCH] Remove package-wide kubebuilder:validation:optional annotation Kubebuilder will deduce the optional attribute from the JSON annotations, if unspecified. Add all the missing omitempty JSON annotations for truly optional fields, which is the right choice in 99% of the cases anyway. Also add some missing default annotations along the way. Overall, this brings the CRDs more in sync to what k0s actually expects at runtime, while omitting the rendering of useless zero values in JSON/ YAML representations. Signed-off-by: Tom Wieczorek --- docs/configuration.md | 12 +- pkg/apis/autopilot/v1beta2/updateconfig.go | 2 +- pkg/apis/k0s/v1beta1/calico.go | 40 ++--- pkg/apis/k0s/v1beta1/clusterconfig_types.go | 2 - pkg/apis/k0s/v1beta1/controltypes.go | 4 +- pkg/apis/k0s/v1beta1/cplb.go | 5 +- pkg/apis/k0s/v1beta1/dualstack.go | 4 +- pkg/apis/k0s/v1beta1/extensions.go | 31 ++-- pkg/apis/k0s/v1beta1/feature_gates.go | 13 +- pkg/apis/k0s/v1beta1/images.go | 31 ++-- pkg/apis/k0s/v1beta1/kubeproxy.go | 37 +---- pkg/apis/k0s/v1beta1/kuberouter.go | 24 +-- pkg/apis/k0s/v1beta1/network.go | 22 ++- pkg/apis/k0s/v1beta1/network_test.go | 2 +- pkg/apis/k0s/v1beta1/nllb.go | 1 + pkg/apis/k0s/v1beta1/storage.go | 21 +-- pkg/apis/k0s/v1beta1/storageextensions.go | 6 +- pkg/apis/k0s/v1beta1/telemetry.go | 3 +- pkg/apis/k0s/v1beta1/workerprofile.go | 2 + pkg/apis/k0s/v1beta1/zz_generated.deepcopy.go | 12 +- ...autopilot.k0sproject.io_updateconfigs.yaml | 5 +- .../k0s.k0sproject.io_clusterconfigs.yaml | 137 +++++++++++++++++- 22 files changed, 263 insertions(+), 153 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index e4615262626b..bb88a155adee 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -59,11 +59,8 @@ spec: controllerManager: {} extensions: helm: - charts: null concurrencyLevel: 5 - repositories: null storage: - create_default_storage_class: false type: external_storage installConfig: users: @@ -76,9 +73,9 @@ spec: adminPort: 8133 agentPort: 8132 network: - calico: null clusterDomain: cluster.local - dualStack: {} + dualStack: + enabled: false kubeProxy: iptables: minSyncPeriod: 0s @@ -94,11 +91,7 @@ spec: kuberouter: autoMTU: true hairpin: Enabled - ipMasq: false metricsPort: 8080 - mtu: 0 - peerRouterASNs: "" - peerRouterIPs: "" nodeLocalLoadBalancing: enabled: false envoyProxy: @@ -111,7 +104,6 @@ spec: scheduler: {} storage: etcd: - externalCluster: null peerAddress: 192.168.68.104 type: etcd telemetry: diff --git a/pkg/apis/autopilot/v1beta2/updateconfig.go b/pkg/apis/autopilot/v1beta2/updateconfig.go index 15997eafa7fa..b08d3a34ad6e 100644 --- a/pkg/apis/autopilot/v1beta2/updateconfig.go +++ b/pkg/apis/autopilot/v1beta2/updateconfig.go @@ -93,7 +93,7 @@ type UpgradeStrategy struct { // +kubebuilder:validation:Enum=periodic;cron Type string `json:"type,omitempty"` // Cron defines the cron expression for the cron upgrade strategy - //+kubebuilder:deprecatedversion:warning="Cron is deprecated and will be removed in 1.29" + // Deprecated: Cron is deprecated and will eventually be ignored Cron string `json:"cron,omitempty"` // Periodic defines the periodic upgrade strategy Periodic PeriodicUpgradeStrategy `json:"periodic,omitempty"` diff --git a/pkg/apis/k0s/v1beta1/calico.go b/pkg/apis/k0s/v1beta1/calico.go index c1b7d4fa5631..07edb1646aae 100644 --- a/pkg/apis/k0s/v1beta1/calico.go +++ b/pkg/apis/k0s/v1beta1/calico.go @@ -21,13 +21,14 @@ import "encoding/json" // Calico defines the calico related config options type Calico struct { // Enable wireguard-based encryption (default: false) - EnableWireguard bool `json:"wireguard"` + EnableWireguard bool `json:"wireguard,omitempty"` // Environment variables to configure Calico node (see https://docs.projectcalico.org/reference/node/configuration) EnvVars map[string]string `json:"envVars,omitempty"` // The host path for Calicos flex-volume-driver(default: /usr/libexec/k0s/kubelet-plugins/volume/exec/nodeagent~uds) - FlexVolumeDriverPath string `json:"flexVolumeDriverPath"` + // +kubebuilder:default="/usr/libexec/k0s/kubelet-plugins/volume/exec/nodeagent~uds" + FlexVolumeDriverPath string `json:"flexVolumeDriverPath,omitempty"` // Host's IP Auto-detection method for Calico (see https://docs.projectcalico.org/reference/node/configuration#ip-autodetection-methods) IPAutodetectionMethod string `json:"ipAutodetectionMethod,omitempty"` @@ -35,34 +36,36 @@ type Calico struct { // Host's IPv6 Auto-detection method for Calico IPv6AutodetectionMethod string `json:"ipV6AutodetectionMethod,omitempty"` - // MTU for overlay network (default: 0) - MTU int `json:"mtu" yaml:"mtu"` + // MTU for overlay network (default: 1450) + // +kubebuilder:default=1450 + MTU int `json:"mtu,omitempty"` // vxlan (default) or ipip - Mode string `json:"mode"` + // +kubebuilder:default=vxlan + Mode string `json:"mode,omitempty"` // Overlay Type (Always, Never or CrossSubnet) - Overlay string `json:"overlay" validate:"oneof=Always Never CrossSubnet" ` + // +kubebuilder:default=Always + Overlay string `json:"overlay,omitempty"` // The UDP port for VXLAN (default: 4789) - VxlanPort int `json:"vxlanPort"` + // +kubebuilder:default=4789 + VxlanPort int `json:"vxlanPort,omitempty"` // The virtual network ID for VXLAN (default: 4096) - VxlanVNI int `json:"vxlanVNI"` + // +kubebuilder:default=4096 + VxlanVNI int `json:"vxlanVNI,omitempty"` } // DefaultCalico returns sane defaults for calico func DefaultCalico() *Calico { return &Calico{ - Mode: "vxlan", - VxlanPort: 4789, - VxlanVNI: 4096, - MTU: 0, - EnableWireguard: false, - FlexVolumeDriverPath: "/usr/libexec/k0s/kubelet-plugins/volume/exec/nodeagent~uds", - Overlay: "Always", - IPAutodetectionMethod: "", - IPv6AutodetectionMethod: "", + Mode: "vxlan", + VxlanPort: 4789, + VxlanVNI: 4096, + MTU: 1450, + FlexVolumeDriverPath: "/usr/libexec/k0s/kubelet-plugins/volume/exec/nodeagent~uds", + Overlay: "Always", } } @@ -72,11 +75,8 @@ func (c *Calico) UnmarshalJSON(data []byte) error { c.VxlanPort = 4789 c.VxlanVNI = 4096 c.MTU = 1450 - c.EnableWireguard = false c.FlexVolumeDriverPath = "/usr/libexec/kubernetes/kubelet-plugins/volume/exec/nodeagent~uds" c.Overlay = "Always" - c.IPAutodetectionMethod = "" - c.IPv6AutodetectionMethod = "" type calico Calico jc := (*calico)(c) diff --git a/pkg/apis/k0s/v1beta1/clusterconfig_types.go b/pkg/apis/k0s/v1beta1/clusterconfig_types.go index d0cb3e0f9214..36d4c3fa8469 100644 --- a/pkg/apis/k0s/v1beta1/clusterconfig_types.go +++ b/pkg/apis/k0s/v1beta1/clusterconfig_types.go @@ -59,8 +59,6 @@ type ClusterConfigStatus struct { // Important: Run "make" to regenerate code after modifying this file } -//+kubebuilder:validation:Optional - // ClusterConfig is the Schema for the clusterconfigs API // // +kubebuilder:object:root=true diff --git a/pkg/apis/k0s/v1beta1/controltypes.go b/pkg/apis/k0s/v1beta1/controltypes.go index af9fe1550d70..86468c3ce07c 100644 --- a/pkg/apis/k0s/v1beta1/controltypes.go +++ b/pkg/apis/k0s/v1beta1/controltypes.go @@ -28,7 +28,9 @@ type CaResponse struct { // EtcdRequest defines the etcd control api request structure type EtcdRequest struct { - Node string `json:"node"` + // +kubebuilder:validation:MinLength=1 + Node string `json:"node"` + // +kubebuilder:validation:MinLength=1 PeerAddress string `json:"peerAddress"` } diff --git a/pkg/apis/k0s/v1beta1/cplb.go b/pkg/apis/k0s/v1beta1/cplb.go index e15827efea18..0689a769212c 100644 --- a/pkg/apis/k0s/v1beta1/cplb.go +++ b/pkg/apis/k0s/v1beta1/cplb.go @@ -38,7 +38,7 @@ type ControlPlaneLoadBalancingSpec struct { // Default: false // +kubebuilder:default=false // +optional - Enabled bool `json:"enabled,omitempty"` + Enabled bool `json:"enabled"` // type indicates the type of the control plane load balancer to deploy on // controller nodes. Currently, the only supported type is "Keepalived". @@ -78,7 +78,6 @@ type VRRPInstance struct { // VirtualIPs is the list of virtual IP address used by the VRRP instance. // Each virtual IP must be a CIDR as defined in RFC 4632 and RFC 4291. // +kubebuilder:validation:MinItems=1 - // +kubebuilder:validation:Required // +listType=set VirtualIPs []string `json:"virtualIPs"` @@ -106,7 +105,6 @@ type VRRPInstance struct { // AuthPass must be 8 characters or less. // +kubebuilder:validation:MinLength=1 // +kubebuilder:validation:MaxLength=8 - // +kubebuilder:validation:Required AuthPass string `json:"authPass"` } @@ -167,7 +165,6 @@ type VirtualServers []VirtualServer // VirtualServer defines the configuration options for a virtual server. type VirtualServer struct { // IPAddress is the virtual IP address used by the virtual server. - // +kubebuilder:validation:Required // +kubebuilder:validation:MinLength=1 IPAddress string `json:"ipAddress"` // DelayLoop is the delay timer for check polling. DelayLoop accepts diff --git a/pkg/apis/k0s/v1beta1/dualstack.go b/pkg/apis/k0s/v1beta1/dualstack.go index 56583cc826ec..c65041f1d788 100644 --- a/pkg/apis/k0s/v1beta1/dualstack.go +++ b/pkg/apis/k0s/v1beta1/dualstack.go @@ -18,7 +18,9 @@ package v1beta1 // DualStack defines network configuration for ipv4\ipv6 mixed cluster setup type DualStack struct { - Enabled bool `json:"enabled,omitempty"` + // +kubebuilder:default=false + // +optional + Enabled bool `json:"enabled"` IPv6PodCIDR string `json:"IPv6podCIDR,omitempty"` IPv6ServiceCIDR string `json:"IPv6serviceCIDR,omitempty"` } diff --git a/pkg/apis/k0s/v1beta1/extensions.go b/pkg/apis/k0s/v1beta1/extensions.go index 9a8074941c50..4aa40ff3aca9 100644 --- a/pkg/apis/k0s/v1beta1/extensions.go +++ b/pkg/apis/k0s/v1beta1/extensions.go @@ -29,15 +29,15 @@ var _ Validateable = (*ClusterExtensions)(nil) // ClusterExtensions specifies cluster extensions type ClusterExtensions struct { //+kubebuilder:deprecatedversion:warning="storage is deprecated and will be ignored in 1.30. https://docs.k0sproject.io/stable/examples/openebs". - Storage *StorageExtension `json:"storage"` - Helm *HelmExtensions `json:"helm"` + Storage *StorageExtension `json:"storage,omitempty"` + Helm *HelmExtensions `json:"helm,omitempty"` } // HelmExtensions specifies settings for cluster helm based extensions type HelmExtensions struct { - ConcurrencyLevel int `json:"concurrencyLevel"` - Repositories RepositoriesSettings `json:"repositories"` - Charts ChartsSettings `json:"charts"` + ConcurrencyLevel int `json:"concurrencyLevel,omitempty"` + Repositories RepositoriesSettings `json:"repositories,omitempty"` + Charts ChartsSettings `json:"charts,omitempty"` } // RepositoriesSettings repository settings @@ -91,15 +91,20 @@ func (he HelmExtensions) Validate() []error { // Chart single helm addon type Chart struct { - Name string `json:"name"` + // +kubebuilder:validation:MinLength=1 + // +kubebuilder:validation:MaxLength=53 + // +kubebuilder:validation:Pattern="[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*" + Name string `json:"name"` + // +kubebuilder:validation:MinLength=1 ChartName string `json:"chartname"` - Version string `json:"version"` - Values string `json:"values"` - TargetNS string `json:"namespace"` + Version string `json:"version,omitempty"` + Values string `json:"values,omitempty"` + // +kubebuilder:validation:MinLength=1 + TargetNS string `json:"namespace"` // Timeout specifies the timeout for how long to wait for the chart installation to finish. // A duration string is a sequence of decimal numbers, each with optional fraction and a unit suffix, such as "300ms" or "2h45m". Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h". - Timeout metav1.Duration `json:"timeout"` - Order int `json:"order"` + Timeout metav1.Duration `json:"timeout,omitempty"` + Order int `json:"order,omitempty"` } // ManifestFileName returns filename to use for the crd manifest @@ -127,10 +132,10 @@ func (c Chart) Validate() error { // Repository describes single repository entry. Fields map to the CLI flags for the "helm add" command type Repository struct { // The repository name. - // +kubebuilder:Validation:Required + // +kubebuilder:validation:MinLength=1 Name string `json:"name"` // The repository URL. - // +kubebuilder:Validation:Required + // +kubebuilder:validation:MinLength=1 URL string `json:"url"` // Whether to skip TLS certificate checks when connecting to the repository. Insecure *bool `json:"insecure,omitempty"` diff --git a/pkg/apis/k0s/v1beta1/feature_gates.go b/pkg/apis/k0s/v1beta1/feature_gates.go index 3f30750b563d..d37208392423 100644 --- a/pkg/apis/k0s/v1beta1/feature_gates.go +++ b/pkg/apis/k0s/v1beta1/feature_gates.go @@ -35,6 +35,8 @@ var KubernetesComponents = []string{ } // FeatureGates collection of feature gate specs +// +listType=map +// +listMapKey=name type FeatureGates []FeatureGate // Validate validates all profiles @@ -86,10 +88,15 @@ func (fgs FeatureGates) AsSliceOfStrings(component string) []string { // FeatureGate specifies single feature gate type FeatureGate struct { // Name of the feature gate - Name string `json:"name,omitempty"` + // +kubebuilder:validation:MinLength=1 + Name string `json:"name"` // Enabled or disabled - Enabled bool `json:"enabled,omitempty"` - // Components to use feature gate on, if empty `KubernetesComponents` is used as the list + Enabled bool `json:"enabled"` + // Components to use feature gate on + // Default: kube-apiserver, kube-controller-manager, kubelet, kube-scheduler, kube-proxy + // +kubebuilder:validation:MinItems=1 + // +kubebuilder:default={kube-apiserver,kube-controller-manager,kubelet,kube-scheduler,kube-proxy} + // +listType=set Components []string `json:"components,omitempty"` } diff --git a/pkg/apis/k0s/v1beta1/images.go b/pkg/apis/k0s/v1beta1/images.go index 9b726df1ec36..4fd1fd3311a9 100644 --- a/pkg/apis/k0s/v1beta1/images.go +++ b/pkg/apis/k0s/v1beta1/images.go @@ -32,7 +32,10 @@ import ( // ImageSpec container image settings type ImageSpec struct { - Image string `json:"image"` + // +kubebuilder:validation:MinLength=1 + Image string `json:"image"` + + // +kubebuilder:validation:Pattern="[\\w][\\w.-]{0,127}" Version string `json:"version"` } @@ -63,15 +66,15 @@ func (s *ImageSpec) URI() string { // ClusterImages sets docker images for addon components type ClusterImages struct { - Konnectivity ImageSpec `json:"konnectivity"` - PushGateway ImageSpec `json:"pushgateway"` - MetricsServer ImageSpec `json:"metricsserver"` - KubeProxy ImageSpec `json:"kubeproxy"` - CoreDNS ImageSpec `json:"coredns"` - Pause ImageSpec `json:"pause"` + Konnectivity ImageSpec `json:"konnectivity,omitempty"` + PushGateway ImageSpec `json:"pushgateway,omitempty"` + MetricsServer ImageSpec `json:"metricsserver,omitempty"` + KubeProxy ImageSpec `json:"kubeproxy,omitempty"` + CoreDNS ImageSpec `json:"coredns,omitempty"` + Pause ImageSpec `json:"pause,omitempty"` - Calico CalicoImageSpec `json:"calico"` - KubeRouter KubeRouterImageSpec `json:"kuberouter"` + Calico CalicoImageSpec `json:"calico,omitempty"` + KubeRouter KubeRouterImageSpec `json:"kuberouter,omitempty"` Repository string `json:"repository,omitempty"` @@ -136,15 +139,15 @@ func (ci *ClusterImages) overrideImageRepositories() { // CalicoImageSpec config group for calico related image settings type CalicoImageSpec struct { - CNI ImageSpec `json:"cni"` - Node ImageSpec `json:"node"` - KubeControllers ImageSpec `json:"kubecontrollers"` + CNI ImageSpec `json:"cni,omitempty"` + Node ImageSpec `json:"node,omitempty"` + KubeControllers ImageSpec `json:"kubecontrollers,omitempty"` } // KubeRouterImageSpec config group for kube-router related images type KubeRouterImageSpec struct { - CNI ImageSpec `json:"cni"` - CNIInstaller ImageSpec `json:"cniInstaller"` + CNI ImageSpec `json:"cni,omitempty"` + CNIInstaller ImageSpec `json:"cniInstaller,omitempty"` } // DefaultClusterImages default image settings diff --git a/pkg/apis/k0s/v1beta1/kubeproxy.go b/pkg/apis/k0s/v1beta1/kubeproxy.go index f74fd3d418c4..2a643e42644b 100644 --- a/pkg/apis/k0s/v1beta1/kubeproxy.go +++ b/pkg/apis/k0s/v1beta1/kubeproxy.go @@ -32,12 +32,12 @@ const ( // KubeProxy defines the configuration for kube-proxy type KubeProxy struct { - Disabled bool `json:"disabled,omitempty"` - Mode string `json:"mode,omitempty"` - MetricsBindAddress string `json:"metricsBindAddress,omitempty"` - IPTables *KubeProxyIPTablesConfiguration `json:"iptables,omitempty"` - IPVS *KubeProxyIPVSConfiguration `json:"ipvs,omitempty"` - NodePortAddresses []string `json:"nodePortAddresses,omitempty"` + Disabled bool `json:"disabled,omitempty"` + Mode string `json:"mode,omitempty"` + MetricsBindAddress string `json:"metricsBindAddress,omitempty"` + IPTables KubeProxyIPTablesConfiguration `json:"iptables,omitempty"` + IPVS KubeProxyIPVSConfiguration `json:"ipvs,omitempty"` + NodePortAddresses []string `json:"nodePortAddresses,omitempty"` } // KubeProxyIPTablesConfiguration contains iptables-related kube-proxy configuration @@ -66,33 +66,8 @@ type KubeProxyIPVSConfiguration struct { // DefaultKubeProxy creates the default config for kube-proxy func DefaultKubeProxy() *KubeProxy { return &KubeProxy{ - Disabled: false, Mode: "iptables", MetricsBindAddress: "0.0.0.0:10249", - IPTables: DefaultKubeProxyIPTables(), - IPVS: DefaultKubeProxyIPVS(), - } -} - -func DefaultKubeProxyIPTables() *KubeProxyIPTablesConfiguration { - return &KubeProxyIPTablesConfiguration{ - MasqueradeAll: false, - SyncPeriod: metav1.Duration{Duration: 0}, - MinSyncPeriod: metav1.Duration{Duration: 0}, - MasqueradeBit: nil, - } -} - -func DefaultKubeProxyIPVS() *KubeProxyIPVSConfiguration { - return &KubeProxyIPVSConfiguration{ - ExcludeCIDRs: nil, - Scheduler: "", - SyncPeriod: metav1.Duration{Duration: 0}, - MinSyncPeriod: metav1.Duration{Duration: 0}, - StrictARP: false, - TCPFinTimeout: metav1.Duration{Duration: 0}, - TCPTimeout: metav1.Duration{Duration: 0}, - UDPTimeout: metav1.Duration{Duration: 0}, } } diff --git a/pkg/apis/k0s/v1beta1/kuberouter.go b/pkg/apis/k0s/v1beta1/kuberouter.go index f867187ee8b5..c2b6e00408bf 100644 --- a/pkg/apis/k0s/v1beta1/kuberouter.go +++ b/pkg/apis/k0s/v1beta1/kuberouter.go @@ -19,25 +19,29 @@ package v1beta1 // KubeRouter defines the kube-router related config options type KubeRouter struct { // Auto-detection of used MTU (default: true) - AutoMTU bool `json:"autoMTU"` + // +kubebuilder:default=true + AutoMTU bool `json:"autoMTU,omitempty"` // Override MTU setting (autoMTU must be set to false) - MTU int `json:"mtu"` + MTU int `json:"mtu,omitempty"` // Kube-router metrics server port. Set to 0 to disable metrics (default: 8080) - MetricsPort int `json:"metricsPort"` + MetricsPort int `json:"metricsPort,omitempty"` // Admits three values: "Enabled" enables it globally, "Allowed" allows but services must be annotated explicitly and "Disabled" // Defaults to "Enabled" // +kubebuilder:default=Enabled - Hairpin Hairpin `json:"hairpin"` - // DEPRECATED: Use hairpin instead. Activates Hairpin Mode (allow a Pod behind a Service to communicate to its own ClusterIP:Port) + Hairpin Hairpin `json:"hairpin,omitempty"` + // Deprecated: Use hairpin instead. Activates Hairpin Mode (allow a Pod behind a Service to communicate to its own ClusterIP:Port) + //+kubebuilder:deprecatedversion:warning="Use hairpin instead. Activates Hairpin Mode (allow a Pod behind a Service to communicate to its own ClusterIP:Port)" HairpinMode bool `json:"hairpinMode,omitempty"` // IP masquerade for traffic originating from the pod network, and destined outside of it (default: false) - IPMasq bool `json:"ipMasq"` + IPMasq bool `json:"ipMasq,omitempty"` // Comma-separated list of global peer addresses - // DEPRECATED: Use extraArgs with peerRouterASNs instead - PeerRouterASNs string `json:"peerRouterASNs"` + // Deprecated: Use extraArgs with peerRouterASNs instead + //+kubebuilder:deprecatedversion:warning="Use extraArgs with peerRouterASNs instead" + PeerRouterASNs string `json:"peerRouterASNs,omitempty"` // Comma-separated list of global peer ASNs - // DEPRECATED: Use extraArgs with peerRouterIPs instead - PeerRouterIPs string `json:"peerRouterIPs"` + // Deprecated: Use extraArgs with peerRouterIPs instead + //+kubebuilder:deprecatedversion:warning="Use extraArgs with peerRouterIPs instead" + PeerRouterIPs string `json:"peerRouterIPs,omitempty"` // ExtraArgs are extra arguments to pass to kube-router // Can be also used to override the default k0s managed kube-router arguments ExtraArgs map[string]string `json:"extraArgs,omitempty"` diff --git a/pkg/apis/k0s/v1beta1/network.go b/pkg/apis/k0s/v1beta1/network.go index 7a639688d93a..bf74258bd4b2 100644 --- a/pkg/apis/k0s/v1beta1/network.go +++ b/pkg/apis/k0s/v1beta1/network.go @@ -31,11 +31,11 @@ var _ Validateable = (*Network)(nil) // Network defines the network related config options type Network struct { - Calico *Calico `json:"calico"` + Calico *Calico `json:"calico,omitempty"` DualStack DualStack `json:"dualStack,omitempty"` - KubeProxy *KubeProxy `json:"kubeProxy"` - KubeRouter *KubeRouter `json:"kuberouter"` + KubeProxy *KubeProxy `json:"kubeProxy,omitempty"` + KubeRouter *KubeRouter `json:"kuberouter,omitempty"` // NodeLocalLoadBalancing defines the configuration options related to k0s's // node-local load balancing feature. @@ -47,12 +47,17 @@ type Network struct { ControlPlaneLoadBalancing *ControlPlaneLoadBalancingSpec `json:"controlPlaneLoadBalancing,omitempty"` // Pod network CIDR to use in the cluster - PodCIDR string `json:"podCIDR"` + // +kubebuilder:default="10.244.0.0/16" + PodCIDR string `json:"podCIDR,omitempty"` // Network provider (valid values: calico, kuberouter, or custom) - Provider string `json:"provider"` + // +kubebuilder:validation:Enum=kuberouter;calico;custom + // +kubebuilder:default=kuberouter + Provider string `json:"provider,omitempty"` // Network CIDR to use for cluster VIP services + // +kubebuilder:default="10.96.0.0/12" ServiceCIDR string `json:"serviceCIDR,omitempty"` // Cluster Domain + // +kubebuilder:default="cluster.local" ClusterDomain string `json:"clusterDomain,omitempty"` } @@ -191,13 +196,6 @@ func (n *Network) UnmarshalJSON(data []byte) error { if n.KubeProxy == nil { n.KubeProxy = DefaultKubeProxy() - } else { - if n.KubeProxy.IPTables == nil { - n.KubeProxy.IPTables = DefaultKubeProxyIPTables() - } - if n.KubeProxy.IPVS == nil { - n.KubeProxy.IPVS = DefaultKubeProxyIPVS() - } } return nil diff --git a/pkg/apis/k0s/v1beta1/network_test.go b/pkg/apis/k0s/v1beta1/network_test.go index e0217ac21570..ae7a881765e6 100644 --- a/pkg/apis/k0s/v1beta1/network_test.go +++ b/pkg/apis/k0s/v1beta1/network_test.go @@ -127,7 +127,7 @@ spec: s.Equal("calico", n.Provider) s.NotNil(n.Calico) s.Equal(4789, n.Calico.VxlanPort) - s.Equal(0, n.Calico.MTU) + s.Equal(1450, n.Calico.MTU) s.Equal("vxlan", n.Calico.Mode) } diff --git a/pkg/apis/k0s/v1beta1/nllb.go b/pkg/apis/k0s/v1beta1/nllb.go index ecdb935cd999..a1007de68a01 100644 --- a/pkg/apis/k0s/v1beta1/nllb.go +++ b/pkg/apis/k0s/v1beta1/nllb.go @@ -34,6 +34,7 @@ type NodeLocalLoadBalancing struct { // enabled indicates if node-local load balancing should be used to access // Kubernetes API servers from worker nodes. // Default: false + // +kubebuilder:default=false // +optional Enabled bool `json:"enabled"` diff --git a/pkg/apis/k0s/v1beta1/storage.go b/pkg/apis/k0s/v1beta1/storage.go index e1eecc2ec451..a2bdb151bed1 100644 --- a/pkg/apis/k0s/v1beta1/storage.go +++ b/pkg/apis/k0s/v1beta1/storage.go @@ -42,17 +42,19 @@ var _ Validateable = (*StorageSpec)(nil) // StorageSpec defines the storage related config options type StorageSpec struct { - Etcd *EtcdConfig `json:"etcd"` + Etcd *EtcdConfig `json:"etcd,omitempty"` Kine *KineConfig `json:"kine,omitempty"` // Type of the data store (valid values:etcd or kine) - Type string `json:"type"` + // +kubebuilder:validation:Enum=etcd;kine + // +kubebuilder:default="etcd" + Type string `json:"type,omitempty"` } // KineConfig defines the Kine related config options type KineConfig struct { // kine datasource URL - DataSource string `json:"dataSource"` + DataSource string `json:"dataSource,omitempty"` } // DefaultStorageSpec creates StorageSpec with sane defaults @@ -121,10 +123,10 @@ func (s *StorageSpec) Validate() []error { // EtcdConfig defines etcd related config options type EtcdConfig struct { // ExternalCluster defines external etcd cluster related config options - ExternalCluster *ExternalCluster `json:"externalCluster"` + ExternalCluster *ExternalCluster `json:"externalCluster,omitempty"` // Node address used for etcd cluster peering - PeerAddress string `json:"peerAddress"` + PeerAddress string `json:"peerAddress,omitempty"` // Map of key-values (strings) for any extra arguments you want to pass down to the etcd process ExtraArgs map[string]string `json:"extraArgs,omitempty"` @@ -133,19 +135,20 @@ type EtcdConfig struct { // ExternalCluster defines external etcd cluster related config options type ExternalCluster struct { // Endpoints of external etcd cluster used to connect by k0s + // +kubebuilder:validation:MinItems=1 Endpoints []string `json:"endpoints"` // EtcdPrefix is a prefix to prepend to all resource paths in etcd - EtcdPrefix string `json:"etcdPrefix"` + EtcdPrefix string `json:"etcdPrefix,omitempty"` // CaFile is the host path to a file with CA certificate - CaFile string `json:"caFile"` + CaFile string `json:"caFile,omitempty"` // ClientCertFile is the host path to a file with TLS certificate for etcd client - ClientCertFile string `json:"clientCertFile"` + ClientCertFile string `json:"clientCertFile,omitempty"` // ClientKeyFile is the host path to a file with TLS key for etcd client - ClientKeyFile string `json:"clientKeyFile"` + ClientKeyFile string `json:"clientKeyFile,omitempty"` } // DefaultEtcdConfig creates EtcdConfig with sane defaults diff --git a/pkg/apis/k0s/v1beta1/storageextensions.go b/pkg/apis/k0s/v1beta1/storageextensions.go index a79b990d038a..f105630d4d45 100644 --- a/pkg/apis/k0s/v1beta1/storageextensions.go +++ b/pkg/apis/k0s/v1beta1/storageextensions.go @@ -20,8 +20,10 @@ import "fmt" // StorageExtenstion specifies cluster default storage type StorageExtension struct { - Type string `json:"type"` - CreateDefaultStorageClass bool `json:"create_default_storage_class"` + // +kubebuilder:validation:Enum=external_storage;openebs_local_storage + Type string `json:"type"` + // +optional + CreateDefaultStorageClass bool `json:"create_default_storage_class,omitempty"` } var _ Validateable = (*StorageExtension)(nil) diff --git a/pkg/apis/k0s/v1beta1/telemetry.go b/pkg/apis/k0s/v1beta1/telemetry.go index e498b743e34a..26716cc3d86b 100644 --- a/pkg/apis/k0s/v1beta1/telemetry.go +++ b/pkg/apis/k0s/v1beta1/telemetry.go @@ -20,7 +20,8 @@ var _ Validateable = (*ClusterTelemetry)(nil) // ClusterTelemetry holds telemetry related settings type ClusterTelemetry struct { - Enabled bool `json:"enabled"` + // +kubebuilder:default=true + Enabled bool `json:"enabled,omitempty"` } // DefaultClusterTelemetry default settings diff --git a/pkg/apis/k0s/v1beta1/workerprofile.go b/pkg/apis/k0s/v1beta1/workerprofile.go index ee6108721879..6eae0b61489c 100644 --- a/pkg/apis/k0s/v1beta1/workerprofile.go +++ b/pkg/apis/k0s/v1beta1/workerprofile.go @@ -26,6 +26,8 @@ import ( var _ Validateable = (*WorkerProfiles)(nil) // WorkerProfiles profiles collection +// +listType=map +// +listMapKey=name type WorkerProfiles []WorkerProfile // Validate validates all profiles diff --git a/pkg/apis/k0s/v1beta1/zz_generated.deepcopy.go b/pkg/apis/k0s/v1beta1/zz_generated.deepcopy.go index b266fd07241b..8357ecc25fd5 100644 --- a/pkg/apis/k0s/v1beta1/zz_generated.deepcopy.go +++ b/pkg/apis/k0s/v1beta1/zz_generated.deepcopy.go @@ -713,16 +713,8 @@ func (in *KonnectivitySpec) DeepCopy() *KonnectivitySpec { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *KubeProxy) DeepCopyInto(out *KubeProxy) { *out = *in - if in.IPTables != nil { - in, out := &in.IPTables, &out.IPTables - *out = new(KubeProxyIPTablesConfiguration) - (*in).DeepCopyInto(*out) - } - if in.IPVS != nil { - in, out := &in.IPVS, &out.IPVS - *out = new(KubeProxyIPVSConfiguration) - (*in).DeepCopyInto(*out) - } + in.IPTables.DeepCopyInto(&out.IPTables) + in.IPVS.DeepCopyInto(&out.IPVS) if in.NodePortAddresses != nil { in, out := &in.NodePortAddresses, &out.NodePortAddresses *out = make([]string, len(*in)) diff --git a/static/manifests/autopilot/CustomResourceDefinition/autopilot.k0sproject.io_updateconfigs.yaml b/static/manifests/autopilot/CustomResourceDefinition/autopilot.k0sproject.io_updateconfigs.yaml index 7102b58f382c..2c0834c6c839 100644 --- a/static/manifests/autopilot/CustomResourceDefinition/autopilot.k0sproject.io_updateconfigs.yaml +++ b/static/manifests/autopilot/CustomResourceDefinition/autopilot.k0sproject.io_updateconfigs.yaml @@ -244,8 +244,9 @@ spec: this update config properties: cron: - description: Cron defines the cron expression for the cron upgrade - strategy + description: |- + Cron defines the cron expression for the cron upgrade strategy + Deprecated: Cron is deprecated and will eventually be ignored type: string periodic: description: Periodic defines the periodic upgrade strategy diff --git a/static/manifests/k0s/CustomResourceDefinition/k0s.k0sproject.io_clusterconfigs.yaml b/static/manifests/k0s/CustomResourceDefinition/k0s.k0sproject.io_clusterconfigs.yaml index b81c5b7b5443..e5892e224415 100644 --- a/static/manifests/k0s/CustomResourceDefinition/k0s.k0sproject.io_clusterconfigs.yaml +++ b/static/manifests/k0s/CustomResourceDefinition/k0s.k0sproject.io_clusterconfigs.yaml @@ -99,10 +99,15 @@ spec: description: Chart single helm addon properties: chartname: + minLength: 1 type: string name: + maxLength: 53 + minLength: 1 + pattern: '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*' type: string namespace: + minLength: 1 type: string order: type: integer @@ -115,6 +120,10 @@ spec: type: string version: type: string + required: + - chartname + - name + - namespace type: object type: array concurrencyLevel: @@ -143,16 +152,21 @@ spec: type: string name: description: The repository name. + minLength: 1 type: string password: description: Password for Basic HTTP authentication. type: string url: description: The repository URL. + minLength: 1 type: string username: description: Username for Basic HTTP authentication. type: string + required: + - name + - url type: object type: array type: object @@ -162,7 +176,12 @@ spec: create_default_storage_class: type: boolean type: + enum: + - external_storage + - openebs_local_storage type: string + required: + - type type: object type: object featureGates: @@ -171,19 +190,35 @@ spec: description: FeatureGate specifies single feature gate properties: components: - description: Components to use feature gate on, if empty `KubernetesComponents` - is used as the list + default: + - kube-apiserver + - kube-controller-manager + - kubelet + - kube-scheduler + - kube-proxy + description: |- + Components to use feature gate on + Default: kube-apiserver, kube-controller-manager, kubelet, kube-scheduler, kube-proxy items: type: string + minItems: 1 type: array + x-kubernetes-list-type: set enabled: description: Enabled or disabled type: boolean name: description: Name of the feature gate + minLength: 1 type: string + required: + - enabled + - name type: object type: array + x-kubernetes-list-map-keys: + - name + x-kubernetes-list-type: map images: description: ClusterImages sets docker images for addon components properties: @@ -195,34 +230,54 @@ spec: description: ImageSpec container image settings properties: image: + minLength: 1 type: string version: + pattern: '[\w][\w.-]{0,127}' type: string + required: + - image + - version type: object kubecontrollers: description: ImageSpec container image settings properties: image: + minLength: 1 type: string version: + pattern: '[\w][\w.-]{0,127}' type: string + required: + - image + - version type: object node: description: ImageSpec container image settings properties: image: + minLength: 1 type: string version: + pattern: '[\w][\w.-]{0,127}' type: string + required: + - image + - version type: object type: object coredns: description: ImageSpec container image settings properties: image: + minLength: 1 type: string version: + pattern: '[\w][\w.-]{0,127}' type: string + required: + - image + - version type: object default_pull_policy: default: IfNotPresent @@ -235,17 +290,27 @@ spec: description: ImageSpec container image settings properties: image: + minLength: 1 type: string version: + pattern: '[\w][\w.-]{0,127}' type: string + required: + - image + - version type: object kubeproxy: description: ImageSpec container image settings properties: image: + minLength: 1 type: string version: + pattern: '[\w][\w.-]{0,127}' type: string + required: + - image + - version type: object kuberouter: description: KubeRouterImageSpec config group for kube-router @@ -255,42 +320,67 @@ spec: description: ImageSpec container image settings properties: image: + minLength: 1 type: string version: + pattern: '[\w][\w.-]{0,127}' type: string + required: + - image + - version type: object cniInstaller: description: ImageSpec container image settings properties: image: + minLength: 1 type: string version: + pattern: '[\w][\w.-]{0,127}' type: string + required: + - image + - version type: object type: object metricsserver: description: ImageSpec container image settings properties: image: + minLength: 1 type: string version: + pattern: '[\w][\w.-]{0,127}' type: string + required: + - image + - version type: object pause: description: ImageSpec container image settings properties: image: + minLength: 1 type: string version: + pattern: '[\w][\w.-]{0,127}' type: string + required: + - image + - version type: object pushgateway: description: ImageSpec container image settings properties: image: + minLength: 1 type: string version: + pattern: '[\w][\w.-]{0,127}' type: string + required: + - image + - version type: object repository: type: string @@ -345,6 +435,7 @@ spec: (see https://docs.projectcalico.org/reference/node/configuration) type: object flexVolumeDriverPath: + default: /usr/libexec/k0s/kubelet-plugins/volume/exec/nodeagent~uds description: 'The host path for Calicos flex-volume-driver(default: /usr/libexec/k0s/kubelet-plugins/volume/exec/nodeagent~uds)' type: string @@ -356,18 +447,23 @@ spec: description: Host's IPv6 Auto-detection method for Calico type: string mode: + default: vxlan description: vxlan (default) or ipip type: string mtu: - description: 'MTU for overlay network (default: 0)' + default: 1450 + description: 'MTU for overlay network (default: 1450)' type: integer overlay: + default: Always description: Overlay Type (Always, Never or CrossSubnet) type: string vxlanPort: + default: 4789 description: 'The UDP port for VXLAN (default: 4789)' type: integer vxlanVNI: + default: 4096 description: 'The virtual network ID for VXLAN (default: 4096)' type: integer wireguard: @@ -376,6 +472,7 @@ spec: type: boolean type: object clusterDomain: + default: cluster.local description: Cluster Domain type: string controlPlaneLoadBalancing: @@ -531,6 +628,7 @@ spec: IPv6serviceCIDR: type: string enabled: + default: false type: boolean type: object kubeProxy: @@ -593,6 +691,7 @@ spec: options properties: autoMTU: + default: true description: 'Auto-detection of used MTU (default: true)' type: boolean extraArgs: @@ -613,7 +712,7 @@ spec: - Disabled type: string hairpinMode: - description: 'DEPRECATED: Use hairpin instead. Activates Hairpin + description: 'Deprecated: Use hairpin instead. Activates Hairpin Mode (allow a Pod behind a Service to communicate to its own ClusterIP:Port)' type: boolean @@ -632,12 +731,12 @@ spec: peerRouterASNs: description: |- Comma-separated list of global peer addresses - DEPRECATED: Use extraArgs with peerRouterASNs instead + Deprecated: Use extraArgs with peerRouterASNs instead type: string peerRouterIPs: description: |- Comma-separated list of global peer ASNs - DEPRECATED: Use extraArgs with peerRouterIPs instead + Deprecated: Use extraArgs with peerRouterIPs instead type: string type: object nodeLocalLoadBalancing: @@ -647,6 +746,7 @@ spec: NOTE: This feature is currently unsupported on ARMv7! properties: enabled: + default: false description: |- enabled indicates if node-local load balancing should be used to access Kubernetes API servers from worker nodes. @@ -673,9 +773,14 @@ spec: used for the Envoy Pod. properties: image: + minLength: 1 type: string version: + pattern: '[\w][\w.-]{0,127}' type: string + required: + - image + - version type: object imagePullPolicy: description: |- @@ -708,13 +813,20 @@ spec: type: string type: object podCIDR: + default: 10.244.0.0/16 description: Pod network CIDR to use in the cluster type: string provider: + default: kuberouter description: 'Network provider (valid values: calico, kuberouter, or custom)' + enum: + - kuberouter + - calico + - custom type: string serviceCIDR: + default: 10.96.0.0/12 description: Network CIDR to use for cluster VIP services type: string type: object @@ -755,11 +867,14 @@ spec: connect by k0s items: type: string + minItems: 1 type: array etcdPrefix: description: EtcdPrefix is a prefix to prepend to all resource paths in etcd type: string + required: + - endpoints type: object extraArgs: additionalProperties: @@ -779,13 +894,18 @@ spec: type: string type: object type: + default: etcd description: Type of the data store (valid values:etcd or kine) + enum: + - etcd + - kine type: string type: object telemetry: description: ClusterTelemetry holds telemetry related settings properties: enabled: + default: true type: boolean type: object workerProfiles: @@ -801,8 +921,13 @@ spec: description: Worker Mapping object type: object x-kubernetes-preserve-unknown-fields: true + required: + - name type: object type: array + x-kubernetes-list-map-keys: + - name + x-kubernetes-list-type: map type: object status: description: ClusterConfigStatus defines the observed state of ClusterConfig