Skip to content

Commit

Permalink
Merge pull request #109151 from Argh4k/r-101566
Browse files Browse the repository at this point in the history
Revert "Field `status.hostIPs` added for Pod (#101566)"
  • Loading branch information
k8s-ci-robot committed Mar 31, 2022
2 parents 3d1e510 + 1108bed commit 691d4c3
Show file tree
Hide file tree
Showing 33 changed files with 1,072 additions and 5,980 deletions.
1,226 changes: 4 additions & 1,222 deletions api/openapi-spec/swagger.json

Large diffs are not rendered by default.

33 changes: 4 additions & 29 deletions api/openapi-spec/v3/api__v1_openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -2609,16 +2609,6 @@
},
"type": "object"
},
"io.k8s.api.core.v1.HostIP": {
"description": "HostIP address information for entries in the (plural) HostIPs field.",
"properties": {
"ip": {
"description": "IP is the IP address assigned to the host",
"type": "string"
}
},
"type": "object"
},
"io.k8s.api.core.v1.HostPathVolumeSource": {
"description": "Represents a host path mapped into a pod. Host path volumes do not support ownership management or SELinux relabeling.",
"properties": {
Expand Down Expand Up @@ -4854,10 +4844,10 @@
"type": "object"
},
"io.k8s.api.core.v1.PodIP": {
"description": "PodIP address information for entries in the (plural) PodIPs field.",
"description": "IP address information for entries in the (plural) PodIPs field. Each entry includes:\n IP: An IP address allocated to the pod. Routable at least within the cluster.",
"properties": {
"ip": {
"description": "IP is the IP address assigned to the pod",
"description": "ip is an IP address (IPv4 or IPv6) assigned to the pod",
"type": "string"
}
},
Expand Down Expand Up @@ -5339,24 +5329,9 @@
"type": "array"
},
"hostIP": {
"description": "hostIP holds the IP address of the host to which the pod is assigned. Empty if the pod has not started yet. A pod can be assigned to a node that has a problem in kubelet which in turns mean that HostIP will not be updated even if there is node is assigned to pod",
"description": "IP address of the host to which the pod is assigned. Empty if not yet scheduled.",
"type": "string"
},
"hostIPs": {
"description": "hostIPs holds the IP addresses allocated to the host. If this field is specified, the first entry must match the hostIP field. This list is empty if the pod has not started yet. A pod can be assigned to a node that has a problem in kubelet which in turns means that HostIPs will not be updated even if there is a node is assigned to this pod.",
"items": {
"allOf": [
{
"$ref": "#/components/schemas/io.k8s.api.core.v1.HostIP"
}
],
"default": {}
},
"type": "array",
"x-kubernetes-list-type": "set",
"x-kubernetes-patch-merge-key": "ip",
"x-kubernetes-patch-strategy": "merge"
},
"initContainerStatuses": {
"description": "The list has one entry per init container in the manifest. The most recent successful init container will have ready = true, the most recently started container will have startTime set. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#pod-and-container-status",
"items": {
Expand Down Expand Up @@ -5389,7 +5364,7 @@
"type": "string"
},
"podIP": {
"description": "podIP address allocated to the pod. Routable at least within the cluster. Empty if not yet allocated.",
"description": "IP address allocated to the pod. Routable at least within the cluster. Empty if not yet allocated.",
"type": "string"
},
"podIPs": {
Expand Down
2,714 changes: 0 additions & 2,714 deletions api/openapi-spec/v3/apis__storage.k8s.io__v1alpha1_openapi.json

This file was deleted.

76 changes: 0 additions & 76 deletions pkg/api/pod/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,6 @@ func GetValidationOptionsFromPodSpecAndMeta(podSpec, oldPodSpec *api.PodSpec, po
AllowExpandedDNSConfig: utilfeature.DefaultFeatureGate.Enabled(features.ExpandedDNSConfig) || haveSameExpandedDNSConfig(podSpec, oldPodSpec),
// Allow pod spec to use OS field
AllowOSField: utilfeature.DefaultFeatureGate.Enabled(features.IdentifyPodOS),
// Allow pod spec to use status.hostIPs in downward API if feature is enabled
AllowHostIPsField: utilfeature.DefaultFeatureGate.Enabled(features.PodHostIPs),
// The default sysctl value does not contain a forward slash, and in 1.24 we intend to relax this to be true by default
AllowSysctlRegexContainSlash: false,
}
Expand All @@ -456,9 +454,6 @@ func GetValidationOptionsFromPodSpecAndMeta(podSpec, oldPodSpec *api.PodSpec, po
// if old spec has OS field set, we must allow it
opts.AllowOSField = opts.AllowOSField || oldPodSpec.OS != nil

// if old spec has status.hostIPs downwardAPI set, we must allow it
opts.AllowHostIPsField = opts.AllowHostIPsField || hasUsedDownwardAPIFieldPathWithPodSpec(oldPodSpec, "status.hostIPs")

// if old spec used non-integer multiple of huge page unit size, we must allow it
opts.AllowIndivisibleHugePagesValues = usesIndivisibleHugePagesValues(oldPodSpec)

Expand All @@ -475,57 +470,6 @@ func GetValidationOptionsFromPodSpecAndMeta(podSpec, oldPodSpec *api.PodSpec, po
return opts
}

func hasUsedDownwardAPIFieldPathWithPodSpec(podSpec *api.PodSpec, fieldPath string) bool {
if podSpec == nil {
return false
}
for _, vol := range podSpec.Volumes {
if hasUsedDownwardAPIFieldPathWithVolume(&vol, fieldPath) {
return true
}
}
for _, c := range podSpec.InitContainers {
if hasUsedDownwardAPIFieldPathWithContainer(&c, fieldPath) {
return true
}
}
for _, c := range podSpec.Containers {
if hasUsedDownwardAPIFieldPathWithContainer(&c, fieldPath) {
return true
}
}
return false
}

func hasUsedDownwardAPIFieldPathWithVolume(volume *api.Volume, fieldPath string) bool {
if volume == nil {
return false
}
if volume.DownwardAPI != nil {
for _, file := range volume.DownwardAPI.Items {
if file.FieldRef != nil &&
file.FieldRef.FieldPath == fieldPath {
return true
}
}
}
return false
}

func hasUsedDownwardAPIFieldPathWithContainer(container *api.Container, fieldPath string) bool {
if container == nil {
return false
}
for _, env := range container.Env {
if env.ValueFrom != nil &&
env.ValueFrom.FieldRef != nil &&
env.ValueFrom.FieldRef.FieldPath == fieldPath {
return true
}
}
return false
}

// GetValidationOptionsFromPodTemplate will return pod validation options for specified template.
func GetValidationOptionsFromPodTemplate(podTemplate, oldPodTemplate *api.PodTemplateSpec) apivalidation.PodValidationOptions {
var newPodSpec, oldPodSpec *api.PodSpec
Expand Down Expand Up @@ -568,39 +512,19 @@ func DropDisabledTemplateFields(podTemplate, oldPodTemplate *api.PodTemplateSpec
func DropDisabledPodFields(pod, oldPod *api.Pod) {
var (
podSpec *api.PodSpec
podStatus *api.PodStatus
podAnnotations map[string]string
oldPodSpec *api.PodSpec
oldPodStatus *api.PodStatus
oldPodAnnotations map[string]string
)
if pod != nil {
podSpec = &pod.Spec
podAnnotations = pod.Annotations
podStatus = &pod.Status
}
if oldPod != nil {
oldPodSpec = &oldPod.Spec
oldPodAnnotations = oldPod.Annotations
oldPodStatus = &oldPod.Status
}
dropDisabledFields(podSpec, podAnnotations, oldPodSpec, oldPodAnnotations)
dropDisabledStatusFields(podStatus, oldPodStatus)
}

// dropDisabledStatusFields removes disabled fields from the pod status
func dropDisabledStatusFields(podStatus *api.PodStatus, oldPodStatus *api.PodStatus) {
// drop HostIPs to empty (disable PodHostIPs).
if !utilfeature.DefaultFeatureGate.Enabled(features.PodHostIPs) && !hostIPsInUse(oldPodStatus) {
podStatus.HostIPs = nil
}
}

func hostIPsInUse(podStatus *api.PodStatus) bool {
if podStatus == nil {
return false
}
return len(podStatus.HostIPs) > 0
}

// dropDisabledFields removes disabled fields from the pod metadata and spec.
Expand Down
70 changes: 0 additions & 70 deletions pkg/api/pod/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1768,73 +1768,3 @@ func TestDropOSField(t *testing.T) {
}
}
}

func TestDropDisabledStatusFields(t *testing.T) {
podWithHostIP := func() *api.PodStatus {
return &api.PodStatus{
HostIPs: makeHostIPs("10.0.0.1", "fd00:10::1"),
}
}

podWithoutHostIPs := func() *api.PodStatus {
return &api.PodStatus{
HostIPs: nil,
}
}

tests := []struct {
name string
podStatus *api.PodStatus
oldPodStatus *api.PodStatus
wantPodStatus *api.PodStatus
featureEnabled bool
}{
{
podStatus: podWithHostIP(),
oldPodStatus: podWithHostIP(),
featureEnabled: false,

wantPodStatus: podWithHostIP(),
},
{
podStatus: podWithoutHostIPs(),
oldPodStatus: podWithHostIP(),
featureEnabled: true,

wantPodStatus: podWithoutHostIPs(),
},
{
podStatus: podWithoutHostIPs(),
oldPodStatus: podWithoutHostIPs(),
featureEnabled: false,

wantPodStatus: podWithoutHostIPs(),
},
{
podStatus: podWithHostIP(),
oldPodStatus: podWithoutHostIPs(),
featureEnabled: true,

wantPodStatus: podWithHostIP(),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.PodHostIPs, tt.featureEnabled)()

dropDisabledStatusFields(tt.podStatus, tt.oldPodStatus)

if !reflect.DeepEqual(tt.podStatus, tt.wantPodStatus) {
t.Errorf("dropDisabledStatusFields() = %v, want %v", tt.podStatus, tt.wantPodStatus)
}
})
}
}

func makeHostIPs(ips ...string) []api.HostIP {
ret := []api.HostIP{}
for _, ip := range ips {
ret = append(ret, api.HostIP{IP: ip})
}
return ret
}
4 changes: 0 additions & 4 deletions pkg/apis/core/fuzzer/fuzzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,6 @@ var Funcs = func(codecs runtimeserializer.CodecFactory) []interface{} {
s.EnableServiceLinks = &enableServiceLinks
}
},
func(s *core.PodStatus, c fuzz.Continue) {
c.Fuzz(&s)
s.HostIPs = []core.HostIP{{IP: s.HostIP}}
},
func(j *core.PodPhase, c fuzz.Continue) {
statuses := []core.PodPhase{core.PodPending, core.PodRunning, core.PodFailed, core.PodUnknown}
*j = statuses[c.Rand.Intn(len(statuses))]
Expand Down
1 change: 0 additions & 1 deletion pkg/apis/core/pods/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ func ConvertDownwardAPIFieldLabel(version, label, value string) (string, string,
"spec.schedulerName",
"status.phase",
"status.hostIP",
"status.hostIPs",
"status.podIP",
"status.podIPs":
return label, value, nil
Expand Down
23 changes: 3 additions & 20 deletions pkg/apis/core/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3212,14 +3212,10 @@ type PodDNSConfigOption struct {
}

// PodIP represents the IP address of a pod.
// IP address information. Each entry includes:
// IP: An IP address allocated to the pod. Routable at least within
// the cluster.
type PodIP struct {
// ip is an IP address assigned to the pod
IP string
}

// HostIP represents the IP address of a host.
type HostIP struct {
// ip is an IP address assigned to the host
IP string
}

Expand Down Expand Up @@ -3360,22 +3356,9 @@ type PodStatus struct {
// give the resources on this node to a higher priority pod that is created after preemption.
// +optional
NominatedNodeName string

// HostIP holds the IP address of the host to which the pod is assigned.
// Empty if the pod has not started yet.
// A pod can be assigned to a node that has a problem in kubelet which in turns mean that HostIP will
// not be updated even if there is node is assigned to pod
// +optional
HostIP string

// HostIPs holds the IP addresses allocated to the host. If this field is specified, the first entry must
// match the hostIP field. This list is empty if the pod has not started yet.
// A pod can be assigned to a node that has a problem in kubelet which in turns means that HostIPs will
// not be updated even if there is a node is assigned to this pod.
// match the hostIP field. This list is empty if no IPs have been allocated yet.
// +optional
HostIPs []HostIP

// PodIPs holds all of the known IP addresses allocated to the pod. Pods may be assigned AT MOST
// one value for each of IPv4 and IPv6.
// +optional
Expand Down
16 changes: 0 additions & 16 deletions pkg/apis/core/v1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,17 +270,6 @@ func Convert_v1_PodStatus_To_core_PodStatus(in *v1.PodStatus, out *core.PodStatu
},
}
}

// If both fields (v1.HostIPs and v1.HostIP) are provided and differ, then HostIP is authoritative for compatibility with older kubelets
if (len(in.HostIP) > 0 && len(in.HostIPs) > 0) && (in.HostIP != in.HostIPs[0].IP) {
out.HostIPs = []core.HostIP{{IP: in.HostIP}}
}
// at the this point, autoConvert copied v1.HostIPs -> core.HostIPs
// if v1.HostIPs was empty but v1.HostIP is not, then set core.HostIPs[0] with v1.HostIP
if len(in.HostIP) > 0 && len(in.HostIPs) == 0 {
out.HostIPs = []core.HostIP{{IP: in.HostIP}}
}

return nil
}

Expand All @@ -294,11 +283,6 @@ func Convert_core_PodStatus_To_v1_PodStatus(in *core.PodStatus, out *v1.PodStatu
if len(in.PodIPs) > 0 {
out.PodIP = in.PodIPs[0].IP
}

// at the this point autoConvert copied core.HostIPs -> v1.HostIPs
if len(in.HostIPs) > 0 {
out.HostIP = in.HostIPs[0].IP
}
return nil
}

Expand Down

0 comments on commit 691d4c3

Please sign in to comment.