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

Lookup PX api port from k8s service #70392

Merged
merged 3 commits into from
Nov 29, 2018
Merged

Conversation

harsh-px
Copy link
Contributor

Fixes #70033

Signed-off-by: Harsh Desai harsh@portworx.com

What type of PR is this?

/kind bug

What this PR does / why we need it: Refer to #70033

Which issue(s) this PR fixes :
Fixes #70033

Special notes for your reviewer:

Fixes an issue where Portworx volumes cannot be mounted if 9001 port is already in use on the host and users remap 9001 to another port.

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Oct 29, 2018
@k8s-ci-robot k8s-ci-robot added sig/storage Categorizes an issue or PR as relevant to SIG Storage. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Oct 29, 2018
@idealhack
Copy link
Member

/kind bug
/ok-to-test

@k8s-ci-robot k8s-ci-robot added kind/bug Categorizes issue or PR as related to a bug. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. labels Oct 30, 2018
func lookupPXAPIPortFromService(svc *v1.Service) int32 {
for _, p := range svc.Spec.Ports {
if p.Port == osdMgmtDefaultPort {
return p.TargetPort.IntVal
Copy link
Member

Choose a reason for hiding this comment

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

What if the service uses named port?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Portworx users use a fixed portworx-service spec generated from https://install.portworx.com. Hence above logic that looks for port and targetPort works.

The spec is

kind: Service
apiVersion: v1
metadata:
  name: portworx-service
  namespace: kube-system
  labels:
    name: portworx
spec:
  selector:
    name: portworx
  ports:
    - name: px-api
      protocol: TCP
      port: 9001
      targetPort: 9001

}

opts := metav1.GetOptions{}
svc, err := kubeClient.CoreV1().Services(api.NamespaceSystem).Get(pxServiceName, opts)
Copy link
Member

Choose a reason for hiding this comment

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

This issues API call for each portworx mount / unmount in kubelet. Can the port number change in a running cluster? Can be the port cached in any way?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jsafrane I've improved this in the incremental commit.

Now I use an existing saved client as long as it's valid. If port changes, a new client will be created and used subsequently.

I have also refactored the methods and created separate methods for getting a client from local calls (mount, unmount, attach and detach) vs cluster wide calls.

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 6, 2018
@harsh-px
Copy link
Contributor Author

harsh-px commented Nov 6, 2018

/retest

@harsh-px
Copy link
Contributor Author

harsh-px commented Nov 6, 2018

/test pull-kubernetes-e2e-kops-aws

@harsh-px
Copy link
Contributor Author

harsh-px commented Nov 9, 2018

@jsafrane Can you take a second look and see if it addressed your comments. Let me know !

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 10, 2018
Harsh Desai added 3 commits November 12, 2018 10:50
Fixes kubernetes#70033

Signed-off-by: Harsh Desai <harsh@portworx.com>
- reused client whenever possible
- refactor get client function into explicit cluster-wide and local functions

Signed-off-by: Harsh Desai <harsh@portworx.com>
Signed-off-by: Harsh Desai <harsh@portworx.com>
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 12, 2018
@jsafrane
Copy link
Member

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 15, 2018
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: harsh-px, jsafrane

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 15, 2018
@k8s-ci-robot k8s-ci-robot merged commit b548d92 into kubernetes:master Nov 29, 2018
k8s-ci-robot added a commit that referenced this pull request Dec 10, 2018
…92-upstream-release-1.13

Automated cherry pick of #70392: Lookup PX api port from k8s service
k8s-ci-robot added a commit that referenced this pull request Jan 4, 2019
…92-upstream-release-1.12

Automated cherry pick of #70392: Lookup PX api port from k8s service
k8s-ci-robot added a commit that referenced this pull request Jan 4, 2019
…92-upstream-release-1.11

Automated cherry pick of #70392: Lookup PX api port from k8s service
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/bug Categorizes issue or PR as related to a bug. 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. sig/storage Categorizes an issue or PR as relevant to SIG Storage. 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.

Portworx volumes cannot be mounted if 9001 port is already in use on the host
4 participants