diff --git a/apps/v1alpha1/collaset_types.go b/apps/v1alpha1/collaset_types.go index f08fd5d..630dd7b 100644 --- a/apps/v1alpha1/collaset_types.go +++ b/apps/v1alpha1/collaset_types.go @@ -56,6 +56,20 @@ const ( DeletePersistentVolumeClaimRetentionPolicyType PersistentVolumeClaimRetentionPolicyType = "Delete" ) +// HostnamePolicyType indicates how the pod's hostname is determined. +// +kubebuilder:validation:Enum=PodName +type HostnamePolicyType string + +const ( + // HostnamePolicyPodName sets the pod's hostname to the pod name. + // This requires namingStrategy.podNamingSuffixPolicy to be PersistentSequence, + // as the pod name must be deterministic before creation. + // The resulting pod name must also be a valid Kubernetes hostname label: + // a single RFC 1123 DNS label containing no dots and no more than 63 characters. + // Otherwise the Pod will be rejected by the API server when the hostname is set. + HostnamePolicyPodName HostnamePolicyType = "PodName" +) + // PodUpdateStrategyType is a string enumeration type that enumerates // all possible ways we can update a Pod when updating application type PodUpdateStrategyType string @@ -123,6 +137,13 @@ type CollaSetSpec struct { // +optional NamingStrategy *NamingStrategy `json:"namingStrategy,omitempty"` + // HostnamePolicy indicates how the pod's hostname is determined. + // When unset (nil), no hostname policy is applied. + // When set to "PodName", the pod's spec.hostname will be set to the pod name. + // This requires NamingStrategy.PodNamingSuffixPolicy to be PersistentSequence. + // +optional + HostnamePolicy *HostnamePolicyType `json:"hostnamePolicy,omitempty"` + // Indicate the number of histories to be conserved // If unspecified, defaults to 20 // +optional diff --git a/apps/v1alpha1/zz_generated.deepcopy.go b/apps/v1alpha1/zz_generated.deepcopy.go index a5f38db..4377108 100644 --- a/apps/v1alpha1/zz_generated.deepcopy.go +++ b/apps/v1alpha1/zz_generated.deepcopy.go @@ -249,6 +249,11 @@ func (in *CollaSetSpec) DeepCopyInto(out *CollaSetSpec) { *out = new(NamingStrategy) **out = **in } + if in.HostnamePolicy != nil { + in, out := &in.HostnamePolicy, &out.HostnamePolicy + *out = new(HostnamePolicyType) + **out = **in + } return } diff --git a/config/crd/apps/apps.kusionstack.io_collasets.yaml b/config/crd/apps/apps.kusionstack.io_collasets.yaml index 16e6dab..4ba2ab0 100644 --- a/config/crd/apps/apps.kusionstack.io_collasets.yaml +++ b/config/crd/apps/apps.kusionstack.io_collasets.yaml @@ -83,6 +83,15 @@ spec: If unspecified, defaults to 20 format: int32 type: integer + hostnamePolicy: + description: |- + HostnamePolicy indicates how the pod's hostname is determined. + When unset (nil), no hostname policy is applied. + When set to "PodName", the pod's spec.hostname will be set to the pod name. + This requires NamingStrategy.PodNamingSuffixPolicy to be PersistentSequence. + enum: + - PodName + type: string namingStrategy: description: NamigPolicy indicates the strategy detail that will be used for replica naming