Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove package-wide kubebuilder:validation:optional annotation #4674

Merged
merged 3 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions cmd/config/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ limitations under the License.
package config

import (
"fmt"

"github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"sigs.k8s.io/yaml"

"github.com/k0sproject/k0s/pkg/apis/k0s/v1beta1"
k0sscheme "github.com/k0sproject/k0s/pkg/client/clientset/scheme"
"github.com/k0sproject/k0s/pkg/config"
)

Expand All @@ -39,12 +39,19 @@ func NewCreateCmd() *cobra.Command {
config.Spec.Network.NodeLocalLoadBalancing.EnvoyProxy.Image = nil
}

cfg, err := yaml.Marshal(config)
var u unstructured.Unstructured
if err := k0sscheme.Scheme.Convert(config, &u, nil); err != nil {
return err
}
unstructured.RemoveNestedField(u.Object, "metadata", "creationTimestamp")

cfg, err := yaml.Marshal(&u)
if err != nil {
return err
}
fmt.Fprintf(cmd.OutOrStdout(), "%s", cfg)
return nil

_, err = cmd.OutOrStdout().Write(cfg)
return err
},
}
cmd.Flags().BoolVar(&includeImages, "include-images", false, "include the default images in the output")
Expand Down
31 changes: 11 additions & 20 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ metadata:
spec:
api:
address: 192.168.68.104
externalAddress: my-lb-address.example.com
k0sApiPort: 9443
port: 6443
sans:
Expand All @@ -61,8 +60,6 @@ spec:
extensions:
helm:
concurrencyLevel: 5
charts: null
repositories: null
installConfig:
users:
etcdUser: etcd
Expand All @@ -74,21 +71,25 @@ spec:
adminPort: 8133
agentPort: 8132
network:
calico: null
clusterDomain: cluster.local
dualStack: {}
dualStack:
enabled: false
kubeProxy:
iptables:
minSyncPeriod: 0s
syncPeriod: 0s
ipvs:
minSyncPeriod: 0s
syncPeriod: 0s
tcpFinTimeout: 0s
tcpTimeout: 0s
udpTimeout: 0s
metricsBindAddress: 0.0.0.0:10249
mode: iptables
kuberouter:
autoMTU: true
hairpin: Enabled
ipMasq: false
metricsPort: 8080
mtu: 0
peerRouterASNs: ""
peerRouterIPs: ""
extraArgs:
nodeLocalLoadBalancing:
enabled: false
envoyProxy:
Expand All @@ -101,20 +102,10 @@ spec:
scheduler: {}
storage:
etcd:
externalCluster: null
peerAddress: 192.168.68.104
type: etcd
telemetry:
enabled: true
featureGates:
- name: feature_XXX
enabled: true
components: ["kubelet", "kube-api", "kube-scheduler"]
- name: feature_YYY
enabled: true
-
name: feature_ZZZ
enabled: false
```

## `spec` Key Detail
Expand Down
3 changes: 2 additions & 1 deletion inttest/configchange/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/kubernetes"
"k8s.io/utils/ptr"

"github.com/k0sproject/k0s/inttest/common"
"github.com/stretchr/testify/suite"
Expand Down Expand Up @@ -139,7 +140,7 @@ func (s *ConfigSuite) TestK0sGetsUp() {
s.Require().NoError(err)
newConfig := originalConfig.DeepCopy()
newConfig.Spec.Network = v1beta1.DefaultNetwork()
newConfig.Spec.Network.KubeRouter.AutoMTU = false
newConfig.Spec.Network.KubeRouter.AutoMTU = ptr.To(false)
newConfig.Spec.Network.KubeRouter.MTU = 1300

// Get the resource version for current kuberouter configmap
Expand Down
4 changes: 1 addition & 3 deletions pkg/apis/autopilot/v1beta2/updateconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ type UpdateSpec struct {
// UpdateStrategy defines the update strategy to use for this update config
UpgradeStrategy UpgradeStrategy `json:"upgradeStrategy,omitempty"`
// PlanSpec defines the plan spec to use for this update config
// +kubebuilder:Validation:Required
PlanSpec AutopilotPlanSpec `json:"planSpec,omitempty"`
}

Expand Down Expand Up @@ -94,8 +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:validation:Optional
//+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"`
Expand Down
6 changes: 1 addition & 5 deletions pkg/apis/etcd/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,12 @@ const (
)

type JoinCondition struct {
// +kubebuilder:validation:Required
// +kubebuilder:validation:Enum=Joined
Type ConditionType `json:"type"`
// +kubebuilder:validation:Required
Type ConditionType `json:"type"`
Status ConditionStatus `json:"status"`
// Last time the condition transitioned from one status to another.
// +optional
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`
// Human-readable message indicating details about last transition.
// +optional
Message string `json:"message,omitempty" protobuf:"bytes,6,opt,name=message"`
}

Expand Down
1 change: 0 additions & 1 deletion pkg/apis/helm/v1beta1/chart_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ type ChartStatus struct {
// +kubebuilder:subresource:status
// +genclient
// +genclient:onlyVerbs=create,delete,list,get,watch,update
// +groupName=helm.k0sproject.io
// Chart is the Schema for the charts API
type Chart struct {
metav1.TypeMeta `json:",inline"`
Expand Down
6 changes: 0 additions & 6 deletions pkg/apis/k0s/v1beta1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,33 +35,27 @@ var _ Validateable = (*APISpec)(nil)
// APISpec defines the settings for the K0s API
type APISpec struct {
// Address on which to connect to the API server.
// +optional
Address string `json:"address,omitempty"`

// The loadbalancer address (for k0s controllers running behind a loadbalancer)
// +optional
ExternalAddress string `json:"externalAddress,omitempty"`

// Map of key-values (strings) for any extra arguments to pass down to Kubernetes api-server process
// +optional
ExtraArgs map[string]string `json:"extraArgs,omitempty"`

// Custom port for k0s-api server to listen on (default: 9443)
// +kubebuilder:validation:Minimum=1
// +kubebuilder:validation:Maximum=65535
// +kubebuilder:default=9443
// +optional
K0sAPIPort int `json:"k0sApiPort,omitempty"`

// Custom port for kube-api server to listen on (default: 6443)
// +kubebuilder:validation:Minimum=1
// +kubebuilder:validation:Maximum=65535
// +kubebuilder:default=6443
// +optional
Port int `json:"port,omitempty"`

// List of additional addresses to push to API servers serving the certificate
// +optional
SANs []string `json:"sans,omitempty"`
}

Expand Down
40 changes: 20 additions & 20 deletions pkg/apis/k0s/v1beta1/calico.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,48 +21,51 @@ 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"`

// 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",
}
}

Expand All @@ -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)
Expand Down
10 changes: 4 additions & 6 deletions pkg/apis/k0s/v1beta1/clusterconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,12 @@ type ClusterConfigStatus struct {
// Important: Run "make" to regenerate code after modifying this file
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:validation:Optional
// ClusterConfig is the Schema for the clusterconfigs API
//
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +genclient
// +genclient:onlyVerbs=create,delete,list,get,watch,update
// +groupName=k0s.k0sproject.io

// ClusterConfig is the Schema for the clusterconfigs API
type ClusterConfig struct {
metav1.ObjectMeta `json:"metadata,omitempty"`
metav1.TypeMeta `json:",omitempty,inline"`
Expand Down
4 changes: 3 additions & 1 deletion pkg/apis/k0s/v1beta1/controltypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down
13 changes: 1 addition & 12 deletions pkg/apis/k0s/v1beta1/cplb.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,15 @@ 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".
// +kubebuilder:default=Keepalived
// +optional
Type CPLBType `json:"type,omitempty"`

// Keepalived contains configuration options related to the "Keepalived" type
// of load balancing.
// +optional
Keepalived *KeepalivedSpec `json:"keepalived,omitempty"`
}

Expand Down Expand Up @@ -80,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"`

Expand All @@ -95,22 +92,19 @@ type VRRPInstance struct {
// network must not use the same VirtualRouterID.
// +kubebuilder:validation:Minimum=1
// +kubebuilder:validation:Maximum=255
// +optional
VirtualRouterID int32 `json:"virtualRouterID,omitempty"`

// AdvertIntervalSeconds is the advertisement interval in seconds. Defaults to 1
// second.
// +kubebuilder:validation:Minimum=1
// +kubebuilder:default=1
// +optional
AdvertIntervalSeconds int32 `json:"advertIntervalSeconds,omitempty"`

// AuthPass is the password for accessing VRRPD. This is not a security
// feature but a way to prevent accidental misconfigurations.
// AuthPass must be 8 characters or less.
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=8
// +kubebuilder:validation:Required
AuthPass string `json:"authPass"`
}

Expand Down Expand Up @@ -171,33 +165,28 @@ 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
// microsecond precision. Further precision will be truncated without
// warnings. Defaults to 1m.
// +kubebuilder:default="1m"
// +optional
DelayLoop metav1.Duration `json:"delayLoop,omitempty"`
// LBAlgo is the load balancing algorithm. If not specified, defaults to rr.
// Valid values are rr, wrr, lc, wlc, lblc, dh, sh, sed, nq. For further
// details refer to keepalived documentation.
// +kubebuilder:default=rr
// +optional
LBAlgo KeepalivedLBAlgo `json:"lbAlgo,omitempty"`
// LBKind is the load balancing kind. If not specified, defaults to DR.
// Valid values are NAT DR TUN. For further details refer to keepalived documentation.
// +kubebuilder:default=DR
// +optional
LBKind KeepalivedLBKind `json:"lbKind,omitempty"`
// PersistenceTimeoutSeconds specifies a timeout value for persistent
// connections in seconds. PersistentTimeoutSeconds must be in the range of
// 1-2678400 (31 days). If not specified, defaults to 360 (6 minutes).
// +kubebuilder:validation:Minimum=1
// +kubebuilder:validation:Maximum=2678400
// +kubebuilder:default=360
// +optional
PersistenceTimeoutSeconds int `json:"persistenceTimeoutSeconds,omitempty"`
}

Expand Down
Loading
Loading