Adding new PodSpec field called setHostnameAsFQDN and SetHostnameAsFQDN gate

These changes add a new field, called setHostnameAsFQDN, to the PodSpec. This
field is a bool that will be used to indicate whether we would like
FQDN be set as hostname or not.

This is PART1 of the changes to enable KEP #1797 and addresses #91036
This commit is contained in:
Javier Diaz-Montes 2020-06-01 16:48:33 -04:00
parent e6214389ca
commit 4112d8db20
4 changed files with 35 additions and 0 deletions

View File

@ -438,6 +438,12 @@ func dropDisabledFields(
// does not specify any values for these fields.
podSpec.PreemptionPolicy = nil
}
if !utilfeature.DefaultFeatureGate.Enabled(features.SetHostnameAsFQDN) && !setHostnameAsFQDNInUse(oldPodSpec) {
// Set SetHostnameAsFQDN to nil only if feature is disabled and it is not used
podSpec.SetHostnameAsFQDN = nil
}
}
// dropDisabledRunAsGroupField removes disabled fields from PodSpec related
@ -720,3 +726,11 @@ func multiplePodIPsInUse(podStatus *api.PodStatus) bool {
}
return false
}
// setHostnameAsFQDNInUse returns true if any pod's spec defines setHostnameAsFQDN field.
func setHostnameAsFQDNInUse(podSpec *api.PodSpec) bool {
if podSpec == nil || podSpec.SetHostnameAsFQDN == nil {
return false
}
return *podSpec.SetHostnameAsFQDN
}

View File

@ -2693,6 +2693,12 @@ type PodSpec struct {
// If not specified, the pod will not have a domainname at all.
// +optional
Subdomain string
// If true the pod's hostname will be configured as the pod's FQDN, rather than the leaf name (the default).
// In Linux containers, this means setting the FQDN in the hostname field of the kernel (the nodename field of struct utsname).
// In Windows containers, this means setting the registry value of hostname for the registry key HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters to FQDN.
// If a pod does not have FQDN, this has no effect.
// +optional
SetHostnameAsFQDN *bool
// If specified, the pod's scheduling constraints
// +optional
Affinity *Affinity

View File

@ -592,6 +592,13 @@ const (
//
// Enables usage of any object for volume data source in PVCs
AnyVolumeDataSource featuregate.Feature = "AnyVolumeDataSource"
// owner: @javidiaz
// alpha: v1.19
//
// Allow setting the Fully Qualified Domain Name (FQDN) in the hostname of a Pod. If a Pod does not
// have FQDN, this feature has no effect.
SetHostnameAsFQDN featuregate.Feature = "SetHostnameAsFQDN"
)
func init() {
@ -683,6 +690,7 @@ var defaultKubernetesFeatureGates = map[featuregate.Feature]featuregate.FeatureS
ExternalPolicyForExternalIP: {Default: true, PreRelease: featuregate.GA}, // remove in 1.20
AnyVolumeDataSource: {Default: false, PreRelease: featuregate.Alpha},
DefaultPodTopologySpread: {Default: false, PreRelease: featuregate.Alpha},
SetHostnameAsFQDN: {Default: false, PreRelease: featuregate.Alpha},
// inherited features from generic apiserver, relisted here to get a conflict if it is changed
// unintentionally on either side:

View File

@ -3055,6 +3055,13 @@ type PodSpec struct {
// +listMapKey=topologyKey
// +listMapKey=whenUnsatisfiable
TopologySpreadConstraints []TopologySpreadConstraint `json:"topologySpreadConstraints,omitempty" patchStrategy:"merge" patchMergeKey:"topologyKey" protobuf:"bytes,33,opt,name=topologySpreadConstraints"`
// If true the pod's hostname will be configured as the pod's FQDN, rather than the leaf name (the default).
// In Linux containers, this means setting the FQDN in the hostname field of the kernel (the nodename field of struct utsname).
// In Windows containers, this means setting the registry value of hostname for the registry key HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters to FQDN.
// If a pod does not have FQDN, this has no effect.
// Default to false.
// +optional
SetHostnameAsFQDN *bool `json:"setHostnameAsFQDN,omitempty" protobuf:"varint,35,opt,name=setHostnameAsFQDN"`
}
type UnsatisfiableConstraintAction string