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

Support status.hostIP in downward API #42717

Merged

Conversation

andrewsykim
Copy link
Member

What this PR does / why we need it:
Exposes pod's hostIP (node IP) via downward API.

Which issue this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close that issue when PR gets merged):
fixes #24657

Special notes for your reviewer:
Not sure if there's more documentation that's needed, please point me in the right direction and I will add some :)

@k8s-ci-robot
Copy link
Contributor

Hi @andrewsykim. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with @k8s-bot ok to test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Mar 8, 2017
@k8s-reviewable
Copy link

This change is Reviewable

@andrewsykim andrewsykim changed the title support hostIP in downward API Support hostIP in downward API Mar 8, 2017
@k8s-github-robot k8s-github-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. release-note-label-needed labels Mar 8, 2017
@andrewsykim andrewsykim changed the title Support hostIP in downward API Support status.hostIP in downward API Mar 8, 2017
@liggitt liggitt assigned thockin and unassigned liggitt Mar 8, 2017
@@ -41,11 +41,6 @@ func FormatMap(m map[string]string) (fmtStr string) {
// ExtractFieldPathAsString extracts the field from the given object
// and returns it as a string. The object must be a pointer to an
// API type.
//
// Currently, this API is limited to supporting the fieldpaths:
Copy link
Member Author

Choose a reason for hiding this comment

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

Seemed out of date

@thockin
Copy link
Member

thockin commented Mar 13, 2017

@k8s-bot ok to test

@thockin thockin added approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-label-needed labels Mar 13, 2017
@k8s-github-robot k8s-github-robot added kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API and removed lgtm "Looks good to me", indicates that a PR is ready to be merged. labels Mar 14, 2017
@andrewsykim andrewsykim force-pushed the support-host-ip-downward-api branch from 5570bdc to 22d72ab Compare March 14, 2017 02:24
@andrewsykim
Copy link
Member Author

@thockin seems like HOST_IP="" in the e2e test 🤔. Any ideas why?

@thockin
Copy link
Member

thockin commented Mar 15, 2017

Possible that there's a race between kubelet starting the pod and writing back the status?

@andrewsykim
Copy link
Member Author

andrewsykim commented Mar 16, 2017

At a quick glance of the kubelet code it seems like the PodIP update should happen on the same UpdateStatus call as HostIP, PodIP is defined in the e2e tests so race condition seems unlikely, you definitely know the code better than me so correct me if I'm wrong please :).

Do you know if kubelet for E2E tests run on standalone mode (seems unlikely that it would)? It seems like the kubelet skips setting HostIP in PodStatus in standalone mode. https://github.com/kubernetes/kubernetes/blob/master/pkg/kubelet/kubelet_pods.go#L1175-L1185

@andrewsykim
Copy link
Member Author

^ I'll temporarily skip the check to verify

@smarterclayton
Copy link
Contributor

smarterclayton commented Mar 16, 2017 via email

@andrewsykim
Copy link
Member Author

@smarterclayton this seems relevant to what you're referring to.

@andrewsykim andrewsykim force-pushed the support-host-ip-downward-api branch from 2b282cc to 22d72ab Compare March 16, 2017 05:54
@andrewsykim
Copy link
Member Author

andrewsykim commented Mar 16, 2017

Oh God, what rabbit hole have I gotten myself into 🤦‍♂️ 😛

@smarterclayton
Copy link
Contributor

smarterclayton commented Mar 16, 2017 via email

@andrewsykim
Copy link
Member Author

I dug into the code a bit more and have a better idea of what to do. If we stick with the way podIP is passed into kubelet's runtime it'll avoid any big refactoring at the cost of adding more cruft to the kubelet code (mostly passing in hostIP along with podIP). If we're OK with this I can have the kubelet code updated soon. Let me know what you think @smarterclayton @thockin @pmorie

Copy link
Contributor

@yujuhong yujuhong left a comment

Choose a reason for hiding this comment

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

With the new commit, the PR looks much cleaner.

@@ -617,6 +617,13 @@ func (kl *Kubelet) podFieldSelectorRuntimeValue(fs *v1.ObjectFieldSelector, pod
return pod.Spec.NodeName, nil
case "spec.serviceAccountName":
return pod.Spec.ServiceAccountName, nil
case "status.hostIP":
hostIP, err := kl.GetHostIP()
Copy link
Contributor

Choose a reason for hiding this comment

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

Use kl.getHostIPAnyWay() to make sure we can always get the host IP, even if kubelet hasn't registered yet.

if err != nil {
return "", err
}

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: remove the extra line.

@yujuhong
Copy link
Contributor

yujuhong commented Apr 3, 2017

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 3, 2017
@k8s-github-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: andrewsykim, yujuhong
We suggest the following additional approver: @bgrant0607

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-github-robot
Copy link

Automatic merge from submit-queue

@k8s-github-robot k8s-github-robot merged commit e28cb42 into kubernetes:master Apr 3, 2017
@andrewsykim
Copy link
Member Author

Any chance we can get this cherry picked into the next 1.6 release?

@yujuhong
Copy link
Contributor

yujuhong commented Apr 4, 2017

@andrewsykim, supporting hostIP in the downward API is a feature. We usually cherry-pick bug fixes.

@deitch
Copy link
Contributor

deitch commented Apr 20, 2017

So what is the target release version for this?

@yujuhong
Copy link
Contributor

So what is the target release version for this?

1.7

gerrit-ovirt-org pushed a commit to oVirt/ovirt-containers that referenced this pull request May 19, 2017
Reintroduce auto-registration flow on VDSC container.
Get the external engine address fetching the CN field
on the TLS cert got connecting the engine on its service
address.
Get the node address using kubernetes Environment Variables
since status.hostIP will be available within downward volume
API only with kubernetes 1.7 (see
kubernetes/kubernetes#42717 ).
Since the registration command it's running in a
systemd unit we have to get its env directly from
/proc/1/environ

Change-Id: I4ff7b7999d089aa581b44bf031f62f10fbbaa3cb
Signed-off-by: Simone Tiraboschi <[email protected]>
gerrit-ovirt-org pushed a commit to oVirt/ovirt-containers that referenced this pull request May 19, 2017
Reintroduce auto-registration flow on VDSC container.
Get the external engine address fetching the CN field
on the TLS cert got connecting the engine on its service
address.
Get the node address using kubernetes Environment Variables
since status.hostIP will be available within downward volume
API only with kubernetes 1.7 (see
kubernetes/kubernetes#42717 ).
Since the registration command it's running in a
systemd unit we have to get its env directly from
/proc/1/environ

Change-Id: I4ff7b7999d089aa581b44bf031f62f10fbbaa3cb
Signed-off-by: Simone Tiraboschi <[email protected]>
@@ -74,10 +74,20 @@ var _ = framework.KubeDescribe("Downward API", func() {
},
},
},
{
Name: "HOST_IP",
Copy link
Member

Choose a reason for hiding this comment

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

You added a new field to an existing check without a version block check.

Copy link
Contributor

Choose a reason for hiding this comment

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

ping @andrewsykim , seems you left a bug to fix here :)

Copy link
Member Author

Choose a reason for hiding this comment

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

@timothysc @resouer Thanks for bringing this to my attention :), will try to fix it this week. Is this blocking someones PR from getting in?

Copy link
Member Author

Choose a reason for hiding this comment

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

Seems odd that this would come up as a problem after 6 months

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is a blocker

Copy link
Member

Choose a reason for hiding this comment

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

PR to fix in 1.8.1 is here - #53673

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks Tim, it seems we also version blocked pod IP e2e test for > v1.8 but it was added way back, was that intentional?

Copy link
Contributor

Choose a reason for hiding this comment

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

@andrewsykim I don't think we want to version block pod IP e2e test. I send PR #53772 to split the test case :)

k8s-github-robot pushed a commit that referenced this pull request Oct 13, 2017
Automatic merge from submit-queue (batch tested with PRs 53507, 53772, 52903, 53543). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Split downward API e2e test case for pod/host IP into two

**What this PR does / why we need it**:
Split the test case in order to avoid version block pod IP e2e test.

**Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #
ref: #42717 (comment)

**Special notes for your reviewer**:
/cc @timothysc @andrewsykim
@ralgara
Copy link

ralgara commented Oct 16, 2018

Hi -- any word on this? Just tested status.hostIP and spec.nodeName on v1.10. Both return blank. Need either of these for a service to register with Eureka for existing external clients (not on k8s). E.g.

...
env:
  - name: EUREKA_SVC_HOST
    valueFrom:
      fieldRef:
        fieldPath: status.hostIP

Thanks.

#24657
#42717

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

how can get the hostIP in a pod