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

Identify the cluster in the NewRuntime call #574

Merged
merged 4 commits into from Dec 5, 2017

Conversation

rthallisey
Copy link
Contributor

Describe what this PR does and why we need it:
Contact the openshift version endpoint to verfiy what cluster
the broker is running on. If the openshift endpoint isn't present, the
broker is running on kubernetes.

Changes proposed in this pull request

  • Identify which cluster the broker is running on

Contact the openshift version endpoint to verfiy what cluster
the broker is running on.
@openshift-ci-robot openshift-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Dec 4, 2017
@rthallisey
Copy link
Contributor Author

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling d798afe on rthallisey:runtime into ** on openshift:master**.

Copy link
Contributor

@shawn-hurley shawn-hurley left a comment

Choose a reason for hiding this comment

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

Minor changes/questions but overall LGTM

pkg/app/app.go Outdated
default:
app.log.Error(err.Error())
os.Exit(1)
}

app.log.Debug("Connecting Dao")
app.dao, err = dao.NewDao(app.config.Dao, app.log.Logger)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we handle this error or should we remove the error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We should be handling it in case the etcd config file is not found.

panic(err.Error())
}
log.Info("OpenShift version: %v", kubeServerInfo)
cluster = openshift{}
Copy link
Contributor

Choose a reason for hiding this comment

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

Thinking about the future, can we make these a function that returns a coe?

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 was thinking that the coe interface would stay private so that only functions in the runtime pkg have access to openshift.go and kubernetes.go. That way, the broker only asks for things it understands like "I want a new sandbox to securely create this apb" instead of "I want a few rbac rules, a new service account, and a new namespace".

What did you have in mind for the future with coe?

Copy link
Contributor

Choose a reason for hiding this comment

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

well I am not saying to make it public, I am talking about making an unexported helper method that encapsulates the retrieval of an actual coe structure.

This is for something like the network joining only for openshift and only when a certain plugin is installed. This means that we would want to do extra stuff while creating a coe and it was just a preemptive thing. Once we need it we can always add it as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok I made an assumption of what you meant based on how I was using NewRuntime. If I understand what you mean, you would like something similar to what we have with the kubernetes client? I'll post a revision with that assumption.

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.

Overall LGTM, just one question about starting the runtime.

}
log.Info("OpenShift version: %v", kubeServerInfo)
cluster = openshift{}
case kapierrors.IsNotFound(err) || kapierrors.IsUnauthorized(err) || kapierrors.IsForbidden(err):
Copy link
Member

Choose a reason for hiding this comment

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

If we are accepting the scenario where we are not authorized to access the /version/openshift endpoint, should we not be ensuring we have permission to do work on a kubernetes cluster first?

I'm struggling to ask this question clearly. So I'm going to ask the same question again, worded differently, in the hopes I can communicate the idea. If we are not authorized / forbidden to access the /version/openshift and we are not authorized / forbidden to access /version/kubernetes (assuming there is a k8s version endpoint somewhere), should we fail?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed @djzager. In /pkg/app/app.go, I added a failure case on kubernetes because if this validation fails then we aren't connected to a cluster.

        case kapierrors.IsNotFound(err) || kapierrors.IsUnauthorized(err) || kapierrors.IsForbidden(err):
                app.log.Error("the server could not find the requested resource")
                app.log.Error(err.Error())
                os.Exit(1)

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 227970d on rthallisey:runtime into ** on openshift:master**.

pkg/app/app.go Outdated
@@ -172,21 +172,15 @@ func CreateApp() App {
// Initialize Runtime
agnosticruntime.NewRuntime(app.log.Logger)

app.log.Debug("Connecting Dao")
app.dao, err = dao.NewDao(app.config.Dao, app.log.Logger)

k8scli, err := clients.Kubernetes(app.log.Logger)
Copy link
Member

Choose a reason for hiding this comment

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

I'm curious, based on the answer to my previous question, if this getting of a Kubernetes client, getting a k8s rest client, and checking the k8s version is something we should push down into the NewRuntime function. That way these checks could be collocated and maybe even simplify the error handling on app startup.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This validation could be behind the runtime pkg. Theoretically, the runtime can be something other than k8s or openshift so we shouldn't assume.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 4ef4c5b on rthallisey:runtime into ** on openshift:master**.

@openshift-ci-robot openshift-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 Dec 5, 2017
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 8160b2d on rthallisey:runtime 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.

LGTM

@rthallisey
Copy link
Contributor Author

rthallisey commented Dec 5, 2017

isn't that, even more, reason to move the initialization of the client into just the runtime?

@shawn-hurley's comment disappeared.

Everywhere that we grab the kubernetes client and use it should be a function in runtime. There are numerous cases of this so we'll do that in different patches. Feel free to write them if you see them.

Tag this issue in those PRs: #575

@rthallisey rthallisey merged commit 9f57edc into openshift:master Dec 5, 2017
@rthallisey rthallisey deleted the runtime branch December 5, 2017 19:05
jianzhangbjz pushed a commit to jianzhangbjz/ansible-service-broker that referenced this pull request May 17, 2018
* Identify the cluster in the NewRuntime call

Contact the openshift version endpoint to verfiy what cluster
the broker is running on.

* Capture dao error

* Make sure each instance creation has it's own function

* Move cluster validation to runtime pkg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

None yet

5 participants