Skip to content
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
4 changes: 2 additions & 2 deletions api/addons/v1beta2/clusterresourceset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ type ClusterResourceSet struct {
metav1.ObjectMeta `json:"metadata,omitempty"`

// spec is the desired state of ClusterResourceSet.
// +optional
Spec ClusterResourceSetSpec `json:"spec,omitempty"`
// +required
Spec ClusterResourceSetSpec `json:"spec,omitempty,omitzero"`
// status is the observed state of ClusterResourceSet.
// +optional
Status ClusterResourceSetStatus `json:"status,omitempty,omitzero"`
Expand Down
4 changes: 2 additions & 2 deletions api/addons/v1beta2/clusterresourcesetbinding_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ type ClusterResourceSetBinding struct {
// +optional
metav1.ObjectMeta `json:"metadata,omitempty"`
// spec is the desired state of ClusterResourceSetBinding.
// +optional
Spec ClusterResourceSetBindingSpec `json:"spec,omitempty"`
// +required
Spec ClusterResourceSetBindingSpec `json:"spec,omitempty,omitzero"`
}

// ANCHOR: ClusterResourceSetBindingSpec
Expand Down
3 changes: 2 additions & 1 deletion api/bootstrap/kubeadm/v1beta2/kubeadmconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ var (

// KubeadmConfigSpec defines the desired state of KubeadmConfig.
// Either ClusterConfiguration and InitConfiguration should be defined or the JoinConfiguration should be defined.
// +kubebuilder:validation:MinProperties=1
type KubeadmConfigSpec struct {
// clusterConfiguration along with InitConfiguration are the configurations necessary for the init command
// +optional
Expand Down Expand Up @@ -543,7 +544,7 @@ type KubeadmConfig struct {

// spec is the desired state of KubeadmConfig.
// +optional
Spec KubeadmConfigSpec `json:"spec,omitempty"`
Spec KubeadmConfigSpec `json:"spec,omitempty,omitzero"`
// status is the observed state of KubeadmConfig.
// +optional
Status KubeadmConfigStatus `json:"status,omitempty,omitzero"`
Expand Down
5 changes: 3 additions & 2 deletions api/bootstrap/kubeadm/v1beta2/kubeadmconfigtemplate_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type KubeadmConfigTemplateSpec struct {
}

// KubeadmConfigTemplateResource defines the Template structure.
// +kubebuilder:validation:MinProperties=1
type KubeadmConfigTemplateResource struct {
// metadata is the standard object's metadata.
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
Expand All @@ -38,7 +39,7 @@ type KubeadmConfigTemplateResource struct {

// spec is the desired state of KubeadmConfig.
// +optional
Spec KubeadmConfigSpec `json:"spec,omitempty"`
Spec KubeadmConfigSpec `json:"spec,omitempty,omitzero"`
}

// +kubebuilder:object:root=true
Expand All @@ -56,7 +57,7 @@ type KubeadmConfigTemplate struct {

// spec is the desired state of KubeadmConfigTemplate.
// +optional
Spec KubeadmConfigTemplateSpec `json:"spec,omitempty"`
Spec KubeadmConfigTemplateSpec `json:"spec,omitempty,omitzero"`
}

// +kubebuilder:object:root=true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,8 @@ type KubeadmControlPlaneSpec struct {

// kubeadmConfigSpec is a KubeadmConfigSpec
// to use for initializing and joining machines to the control plane.
// +required
KubeadmConfigSpec bootstrapv1.KubeadmConfigSpec `json:"kubeadmConfigSpec"`
// +optional
KubeadmConfigSpec bootstrapv1.KubeadmConfigSpec `json:"kubeadmConfigSpec,omitempty,omitzero"`

// rolloutBefore is a field to indicate a rollout should be performed
// if the specified criteria is met.
Expand Down Expand Up @@ -807,8 +807,8 @@ type KubeadmControlPlane struct {
metav1.ObjectMeta `json:"metadata,omitempty"`

// spec is the desired state of KubeadmControlPlane.
// +optional
Spec KubeadmControlPlaneSpec `json:"spec,omitempty"`
// +required
Spec KubeadmControlPlaneSpec `json:"spec,omitempty,omitzero"`
// status is the observed state of KubeadmControlPlane.
// +optional
Status KubeadmControlPlaneStatus `json:"status,omitempty,omitzero"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type KubeadmControlPlaneTemplate struct {

// spec is the desired state of KubeadmControlPlaneTemplate.
// +optional
Spec KubeadmControlPlaneTemplateSpec `json:"spec,omitempty"`
Spec KubeadmControlPlaneTemplateSpec `json:"spec,omitempty,omitzero"`
}

// +kubebuilder:object:root=true
Expand All @@ -67,15 +67,16 @@ func init() {
}

// KubeadmControlPlaneTemplateResource describes the data needed to create a KubeadmControlPlane from a template.
// +kubebuilder:validation:MinProperties=1
type KubeadmControlPlaneTemplateResource struct {
// metadata is the standard object's metadata.
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
// +optional
ObjectMeta clusterv1.ObjectMeta `json:"metadata,omitempty"`

// spec is the desired state of KubeadmControlPlaneTemplateResource.
// +required
Spec KubeadmControlPlaneTemplateResourceSpec `json:"spec"`
// +optional
Spec KubeadmControlPlaneTemplateResourceSpec `json:"spec,omitempty,omitzero"`
Comment on lines +78 to +79
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change from required?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it actually is optional and I aligned this here to the same field in KubeadmConfigTemplate which is also optional

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified it is actually optional

}

// KubeadmControlPlaneTemplateResourceSpec defines the desired state of KubeadmControlPlane.
Expand All @@ -91,8 +92,8 @@ type KubeadmControlPlaneTemplateResourceSpec struct {

// kubeadmConfigSpec is a KubeadmConfigSpec
// to use for initializing and joining machines to the control plane.
// +required
KubeadmConfigSpec bootstrapv1.KubeadmConfigSpec `json:"kubeadmConfigSpec"`
// +optional
KubeadmConfigSpec bootstrapv1.KubeadmConfigSpec `json:"kubeadmConfigSpec,omitempty,omitzero"`

// rolloutBefore is a field to indicate a rollout should be performed
// if the specified criteria is met.
Expand Down
5 changes: 3 additions & 2 deletions api/core/v1beta2/cluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ const (
// ANCHOR: ClusterSpec

// ClusterSpec defines the desired state of Cluster.
// +kubebuilder:validation:MinProperties=1
type ClusterSpec struct {
// paused can be used to prevent controllers from processing the Cluster and all its associated objects.
// +optional
Expand Down Expand Up @@ -1185,8 +1186,8 @@ type Cluster struct {
metav1.ObjectMeta `json:"metadata,omitempty"`

// spec is the desired state of Cluster.
// +optional
Spec ClusterSpec `json:"spec,omitempty"`
// +required
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

required because either Cluster.spec.topology or Cluster.spec.controlPlaneRef / infrastructureRef should be set. An empty Cluster does not work

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that validated in a webhook currently? That should be easy to validate in CEL and would make it easier to appreciate that this rule exists

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, there is no validation today. Neither in OpenAPI validation nor in the webhook.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could probably build some ratcheting validation to enforce this in the future, something for the backlog maybe

Copy link
Member Author

@sbueringer sbueringer Jul 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, will track as a follow-up to improve this (we'll also write up the variations of infraRef/cpRef/topology being set/unset that make sense)

Spec ClusterSpec `json:"spec,omitempty,omitzero"`
// status is the observed state of Cluster.
// +optional
Status ClusterStatus `json:"status,omitempty,omitzero"`
Expand Down
5 changes: 3 additions & 2 deletions api/core/v1beta2/clusterclass_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,15 @@ type ClusterClass struct {
metav1.ObjectMeta `json:"metadata,omitempty"`

// spec is the desired state of ClusterClass.
// +optional
Spec ClusterClassSpec `json:"spec,omitempty"`
// +required
Spec ClusterClassSpec `json:"spec,omitempty,omitzero"`
// status is the observed state of ClusterClass.
// +optional
Status ClusterClassStatus `json:"status,omitempty,omitzero"`
}

// ClusterClassSpec describes the desired state of the ClusterClass.
// +kubebuilder:validation:MinProperties=1
type ClusterClassSpec struct {
// availabilityGates specifies additional conditions to include when evaluating Cluster Available condition.
//
Expand Down
4 changes: 2 additions & 2 deletions api/core/v1beta2/machine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -736,8 +736,8 @@ type Machine struct {
metav1.ObjectMeta `json:"metadata,omitempty"`

// spec is the desired state of Machine.
// +optional
Spec MachineSpec `json:"spec,omitempty"`
// +required
Spec MachineSpec `json:"spec,omitempty,omitzero"`
// status is the observed state of Machine.
// +optional
Status MachineStatus `json:"status,omitempty,omitzero"`
Expand Down
4 changes: 2 additions & 2 deletions api/core/v1beta2/machinedeployment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,8 +593,8 @@ type MachineDeployment struct {
metav1.ObjectMeta `json:"metadata,omitempty"`

// spec is the desired state of MachineDeployment.
// +optional
Spec MachineDeploymentSpec `json:"spec,omitempty"`
// +required
Spec MachineDeploymentSpec `json:"spec,omitempty,omitzero"`
// status is the observed state of MachineDeployment.
// +optional
Status MachineDeploymentStatus `json:"status,omitempty,omitzero"`
Expand Down
4 changes: 2 additions & 2 deletions api/core/v1beta2/machinehealthcheck_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ type MachineHealthCheck struct {
metav1.ObjectMeta `json:"metadata,omitempty"`

// spec is the specification of machine health check policy
// +optional
Spec MachineHealthCheckSpec `json:"spec,omitempty"`
// +required
Spec MachineHealthCheckSpec `json:"spec,omitempty,omitzero"`

// status is the most recently observed status of MachineHealthCheck resource
// +optional
Expand Down
4 changes: 2 additions & 2 deletions api/core/v1beta2/machinepool_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,8 @@ type MachinePool struct {
metav1.ObjectMeta `json:"metadata,omitempty"`

// spec is the desired state of MachinePool.
// +optional
Spec MachinePoolSpec `json:"spec,omitempty"`
// +required
Spec MachinePoolSpec `json:"spec,omitempty,omitzero"`
// status is the observed state of MachinePool.
// +optional
Status MachinePoolStatus `json:"status,omitempty,omitzero"`
Expand Down
4 changes: 2 additions & 2 deletions api/core/v1beta2/machineset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,8 @@ type MachineSet struct {
metav1.ObjectMeta `json:"metadata,omitempty"`

// spec is the desired state of MachineSet.
// +optional
Spec MachineSetSpec `json:"spec,omitempty"`
// +required
Spec MachineSetSpec `json:"spec,omitempty,omitzero"`
// status is the observed state of MachineSet.
// +optional
Status MachineSetStatus `json:"status,omitempty,omitzero"`
Expand Down
7 changes: 7 additions & 0 deletions api/core/v1beta2/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions api/ipam/v1beta2/ipaddress_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ type IPAddress struct {
metav1.ObjectMeta `json:"metadata,omitempty"`

// spec is the desired state of IPAddress.
// +optional
Spec IPAddressSpec `json:"spec,omitempty"`
// +required
Spec IPAddressSpec `json:"spec,omitempty,omitzero"`
}

// +kubebuilder:object:root=true
Expand Down
4 changes: 2 additions & 2 deletions api/ipam/v1beta2/ipaddressclaim_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ type IPAddressClaim struct {
metav1.ObjectMeta `json:"metadata,omitempty"`

// spec is the desired state of IPAddressClaim.
// +optional
Spec IPAddressClaimSpec `json:"spec,omitempty"`
// +required
Spec IPAddressClaimSpec `json:"spec,omitempty,omitzero"`
// status is the observed state of IPAddressClaim.
// +optional
Status IPAddressClaimStatus `json:"status,omitempty,omitzero"`
Expand Down
5 changes: 3 additions & 2 deletions api/runtime/v1beta2/extensionconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type ExtensionConfigSpec struct {

// ClientConfig contains the information to make a client
// connection with an Extension server.
// +kubebuilder:validation:MinProperties=1
type ClientConfig struct {
// url gives the location of the Extension server, in standard URL form
// (`scheme://host:port/path`).
Expand Down Expand Up @@ -230,8 +231,8 @@ type ExtensionConfig struct {
metav1.ObjectMeta `json:"metadata,omitempty"`

// spec is the desired state of the ExtensionConfig.
// +optional
Spec ExtensionConfigSpec `json:"spec,omitempty"`
// +required
Spec ExtensionConfigSpec `json:"spec,omitempty,omitzero"`

// status is the current state of the ExtensionConfig
// +optional
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"

bootstrapv1 "sigs.k8s.io/cluster-api/api/bootstrap/kubeadm/v1beta2"
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
"sigs.k8s.io/cluster-api/util/test/builder"
)

Expand All @@ -35,7 +36,11 @@ func TestKubeadmConfigReconciler(t *testing.T) {
ns, err := env.CreateNamespace(ctx, "test-kubeadm-config-reconciler")
g.Expect(err).ToNot(HaveOccurred())

cluster := builder.Cluster(ns.Name, "cluster1").Build()
cluster := builder.Cluster(ns.Name, "cluster1").
WithClusterNetwork(&clusterv1.ClusterNetwork{
ServiceDomain: "service.domain",
}).
Build()
g.Expect(env.Create(ctx, cluster)).To(Succeed())
machine := newWorkerMachineForCluster(cluster)
g.Expect(env.Create(ctx, machine)).To(Succeed())
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions config/crd/bases/cluster.x-k8s.io_clusterclasses.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading