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

pkg/helm: install resources in same namespace as CR #2414

Merged

Conversation

joelanford
Copy link
Member

@joelanford joelanford commented Jan 16, 2020

Description of the change:
This PR fixes a bug that causes all release resources
to be created in the namespace that the helm-operator is deployed
in, not the namespace that the CR is deployed in.

Motivation for the change:
Closes #2416

@openshift-ci-robot openshift-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jan 16, 2020
}

func (c namespaceClientConfig) ClientConfig() (*rest.Config, error) {
return nil, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Why it is required since always return nil and nil?

Copy link
Member Author

Choose a reason for hiding this comment

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

These functions are required because ToRawKubeConfigLoader() needs to return a clientcmd.ClientConfig which is an interface that requires that all of these functions be implemented.

As far as I can tell, Helm only uses ToRawKubeConfigLoader().Namespace() and not the other functions (I'll double check this), so it should be okay for those to be no-ops. We could have those unused functions return fmt.Errorf("not implemented") if that makes sense.

Copy link
Member Author

Choose a reason for hiding this comment

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

Just following up on the question of how ToRawKubeConfigLoader() is used. Here's the grep output from the Helm project:

$ grep -r ToRaw *
pkg/kube/factory.go:	// ToRawKubeConfigLoader return kubeconfig loader as-is
pkg/kube/factory.go:	ToRawKubeConfigLoader() clientcmd.ClientConfig
pkg/kube/client.go:	if ns, _, err := c.Factory.ToRawKubeConfigLoader().Namespace(); err == nil {
pkg/cli/environment.go:	if ns, _, err := s.RESTClientGetter().ToRawKubeConfigLoader().Namespace(); err == nil {

So yeah, only Namespace() actually needs to be implemented.

return c.namespace, false, nil
}

func (c namespaceClientConfig) ConfigAccess() clientcmd.ConfigAccess {
return nil
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

@joelanford
Copy link
Member Author

Before we merge this, I also want to update the e2e helm test to deploy the CR in a separate namespace to prevent this regression in the future.

@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 Jan 17, 2020
@joelanford joelanford requested review from bharathi-tenneti and theishshah and removed request for AlexNPavel January 17, 2020 16:47
@joelanford joelanford assigned joelanford and unassigned joelanford Jan 17, 2020
@joelanford
Copy link
Member Author

@camilamacedo86 PTAL

@estroz estroz added the kind/bug Categorizes issue or PR as related to a bug. label Jan 17, 2020
kubectl create -f "$OPERATORDIR/deploy/crds/helm.example.com_nginxes_crd.yaml"
kubectl create -f "$OPERATORDIR/deploy/operator.yaml"
kubectl create -f "$OPERATORDIR/deploy/service_account.yaml"
kubectl create -f "$OPERATORDIR/deploy/cluster_role.yaml"
Copy link
Member

Choose a reason for hiding this comment

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

The addition of --namespace below makes sense, but why is the test operator now cluster-scoped? Shouldn't its manifests just have a different namespace?

Copy link
Member Author

Choose a reason for hiding this comment

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

The change to the operator.yaml is to make it watch all namespaces so that it can see CRs outside of its own namespace. Not sure if that answers your question...

Copy link
Member

@estroz estroz left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Jan 17, 2020
@joelanford
Copy link
Member Author

Closes #2416

joelanford added a commit to joelanford/operator-sdk that referenced this pull request Jan 17, 2020
@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Jan 17, 2020
}
return kube.New(c), nil
}

Copy link
Contributor

@camilamacedo86 camilamacedo86 Jan 17, 2020

Choose a reason for hiding this comment

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

It as unused before. 👍

This commit fixes a bug that causes all release resources
to be created in the namespace that the operator is deployed
in, not the namespace that the CR is deployed in.
Copy link
Contributor

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

/lgtm
/approved

When Pass in the CI

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Jan 17, 2020
@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Jan 17, 2020
@openshift-ci-robot
Copy link

New changes are detected. LGTM label has been removed.

@joelanford joelanford merged commit aa1c5ea into operator-framework:master Jan 17, 2020
@joelanford joelanford deleted the helm-fix-install-namespace branch January 17, 2020 23:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug. 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.

Helm resources are created in the operator namespace instead of the CR namespace
4 participants