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

Use the Kubernetes API for namespaces check #552

Merged
merged 3 commits into from Nov 15, 2017

Conversation

rthallisey
Copy link
Contributor

@rthallisey rthallisey commented Nov 14, 2017

Describe what this PR does and why we need it:
Verify that a namespace exists using the kubernetes API.

Changes proposed in this pull request

  • Fixes issue in k8s where projects don't exist

We don't need to verify that a namespace exists because we
now use a transient namespace and the client will error
out if you create a serviceinstace in a namespace that doesn't
exist.
@openshift-ci-robot openshift-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Nov 14, 2017
@shawn-hurley
Copy link
Contributor

shawn-hurley commented Nov 14, 2017

NACK, it is assumed that the project is created by the catalog. I think this is a valid check IMO.

This is probably a pretty good place to determine if that assumption makes sense.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 7b2336f on rthallisey:remove-oc-project into ** on openshift:master**.

@rthallisey
Copy link
Contributor Author

You can't create a service instance without a valid namespace/project. I don't think there's a scenario where this code will be false. Let me know if you have one in mind.

[rhallisey@rhev-i16c-04 ansible-service-broker]$ oc create -f  scripts/broker-ci/mediawiki123.yaml 
Error from server (NotFound): error when creating "scripts/broker-ci/mediawiki123.yaml": namespaces "non-existent-namespace" not found

@shawn-hurley
Copy link
Contributor

shawn-hurley commented Nov 14, 2017 via email

Copy link
Member

@djzager djzager left a comment

Choose a reason for hiding this comment

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

I agree with @shawn-hurley on this one. Instead of removing the check entirely, maybe update it to use the k8s api instead of kubectl?

@rthallisey
Copy link
Contributor Author

I think this check came from the asbcli era which used the scenario you mentioned. There isn't any harm in keeping another check around, but I think the scenario where this check fails is going to be rare. I have the patch to convert to a namespace already around. I'll swap to that one.

@rthallisey rthallisey changed the title Remove namespaces check Use the Kubernetes API for namespaces check Nov 14, 2017
Copy link
Member

@djzager djzager left a comment

Choose a reason for hiding this comment

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

LGTM

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling fb27aa4 on rthallisey:remove-oc-project into ** on openshift:master**.

Copy link
Member

@djzager djzager left a comment

Choose a reason for hiding this comment

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

Lint fix then this can be merged

log.Info("Checking if namespace %s exists.", ns)
_, err = k8scli.CoreV1().Namespaces().Get(ns, metav1.GetOptions{})
if err != nil {
return "", nil, errors.New(fmt.Sprintf("Project %s does NOT exist!", ns))
Copy link
Member

Choose a reason for hiding this comment

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

=================================
              Lint               
=================================
pkg/apb/provision_or_update.go:65:19: should replace errors.New(fmt.Sprintf(...)) with fmt.Errorf(...)
Found 1 lint suggestions; failing.
Makefile:27: recipe for target 'lint' failed
make: *** [lint] Error 1

Copy link
Member

@djzager djzager left a comment

Choose a reason for hiding this comment

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

LGTM - again

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 5acde6c on rthallisey:remove-oc-project into ** on openshift:master**.

Copy link
Member

@djzager djzager left a comment

Choose a reason for hiding this comment

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

Another lint issue.

log.Info("Checking if namespace %s exists.", ns)
_, err = k8scli.CoreV1().Namespaces().Get(ns, metav1.GetOptions{})
if err != nil {
return "", nil, fmt.Errorf("Project %s does NOT exist!", ns)
Copy link
Member

Choose a reason for hiding this comment

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

One more 😉

pkg/apb/provision_or_update.go:65:30: error strings should not be capitalized or end with punctuation or a newline

You can use make check to run through most of the tests before pushing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll move back to what was there :).

Copy link
Member

@djzager djzager left a comment

Choose a reason for hiding this comment

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

LGTM

@rthallisey
Copy link
Contributor Author

thanks @djzager

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 3c97560 on rthallisey:remove-oc-project into ** on openshift:master**.

@djzager djzager merged commit c3150f4 into openshift:master Nov 15, 2017
jianzhangbjz pushed a commit to jianzhangbjz/ansible-service-broker that referenced this pull request May 17, 2018
* Remove namespaces check

We don't need to verify that a namespace exists because we
now use a transient namespace and the client will error
out if you create a serviceinstace in a namespace that doesn't
exist.

* Use the namespaces API

* Fix lint test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants