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

Changed to always use namespace when a name is involved #485

Merged

Conversation

jpkrohling
Copy link
Contributor

Fixes #285 by using namespaces whenever a name is involved. Before this change, deploying a Jaeger instance in a namespace tenant2 when there's already a Jaeger instance in another namespace (tenant1) would cause the underlying objects, such as Deployment objects, to be removed in favor of the one in the new namespace.

Signed-off-by: Juraci Paixão Kröhling juraci@kroehling.de

@jpkrohling
Copy link
Contributor Author

jpkrohling commented Jun 28, 2019

@jkandasa , this can be tested as follows:

# make sure the environment is clean:
$ kubectl get deployments --all-namespaces
NAMESPACE     NAME                       READY     UP-TO-DATE   AVAILABLE   AGE
kube-system   coredns                    2/2       2            2           28h
kube-system   default-http-backend       1/1       1            1           28h
kube-system   kubernetes-dashboard       1/1       1            1           28h
kube-system   nginx-ingress-controller   1/1       1            1           28h

$ kubectl create namespace tenant1
namespace/tenant1 created
$ kubectl create namespace tenant2
namespace/tenant2 created
$ kubectl apply -n tenant1 -f deploy/examples/simplest.yaml 
jaeger.jaegertracing.io/simplest created
$ kubectl apply -n tenant2 -f deploy/examples/simplest.yaml 
jaeger.jaegertracing.io/simplest created
$ kubectl get deployments -n tenant1
NAME       READY     UP-TO-DATE   AVAILABLE   AGE
simplest   1/1       1            1           40s
$ kubectl get deployments -n tenant2
NAME       READY     UP-TO-DATE   AVAILABLE   AGE
simplest   1/1       1            1           28s
$ kubectl get jaegers --all-namespaces
NAMESPACE   NAME       AGE
tenant1     simplest   51s
tenant2     simplest   38s

Signed-off-by: Juraci Paixão Kröhling <juraci@kroehling.de>
"github.com/jaegertracing/jaeger-operator/pkg/inventory"
)

func (r *ReconcileJaeger) applyAccounts(jaeger v1.Jaeger, desired []corev1.ServiceAccount) error {
opts := client.MatchingLabels(map[string]string{
opts := client.InNamespace(jaeger.Namespace).MatchingLabels(map[string]string{
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 (and similar changes in the other controller functions) is the actual fix for the reported problem. All other changes are either to make the test more accurate, or to properly log what's going on.

if err := r.client.Update(context.Background(), &d); err != nil {
return err
}
}

for _, d := range inv.Delete {
jaeger.Logger().WithField("account", d.Name).Debug("deleting service account")
jaeger.Logger().WithFields(log.Fields{
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 overrides the namespace from the jaeger.Logger(). Before this change, the log would say that it "deleting service account" in namespace tenant1 when in fact the SA was in the namespace tenant2.

@@ -54,7 +56,7 @@ func ForAccounts(existing []v1.ServiceAccount, desired []v1.ServiceAccount) Acco
func accountMap(deps []v1.ServiceAccount) map[string]v1.ServiceAccount {
m := map[string]v1.ServiceAccount{}
for _, d := range deps {
m[d.Name] = d
m[fmt.Sprintf("%s.%s", d.Namespace, d.Name)] = d
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 kind of change isn't strictly required, as the data it receives should be part of the same namespace. However, it's more accurate to use the namespace in the key, as "tenant1.simplest" shouldn't be seen as the same as "tenant2.simplest". This fix helped me spot the real cause for the bug.

@jpkrohling
Copy link
Contributor Author

@objectiser sorry for such a bit PR. Most of it are changes to the NewJaeger function, affecting pretty much all tests. I left comments in the important parts.

@codecov
Copy link

codecov bot commented Jun 28, 2019

Codecov Report

Merging #485 into master will increase coverage by 0.15%.
The diff coverage is 97.9%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #485      +/-   ##
=========================================
+ Coverage   91.74%   91.9%   +0.15%     
=========================================
  Files          65      64       -1     
  Lines        3199    3272      +73     
=========================================
+ Hits         2935    3007      +72     
- Misses        184     185       +1     
  Partials       80      80
Impacted Files Coverage Δ
pkg/apis/jaegertracing/v1/builder.go 0% <0%> (ø) ⬆️
pkg/inventory/secret.go 100% <100%> (ø) ⬆️
pkg/inventory/deployment.go 100% <100%> (ø) ⬆️
pkg/inventory/account.go 100% <100%> (ø) ⬆️
pkg/controller/jaeger/account.go 74.19% <100%> (+10.55%) ⬆️
pkg/inventory/ingress.go 100% <100%> (ø) ⬆️
pkg/inventory/configmap.go 100% <100%> (ø) ⬆️
pkg/controller/jaeger/service.go 74.19% <100%> (+10.55%) ⬆️
pkg/inventory/daemonset.go 100% <100%> (ø) ⬆️
pkg/controller/jaeger/elasticsearch.go 56.41% <100%> (+5.68%) ⬆️
... and 17 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c802a91...a2deaec. Read the comment docs.

@codecov
Copy link

codecov bot commented Jun 28, 2019

Codecov Report

Merging #485 into master will increase coverage by 0.19%.
The diff coverage is 97.9%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #485      +/-   ##
==========================================
+ Coverage   91.74%   91.94%   +0.19%     
==========================================
  Files          65       65              
  Lines        3199     3290      +91     
==========================================
+ Hits         2935     3025      +90     
- Misses        184      185       +1     
  Partials       80       80
Impacted Files Coverage Δ
pkg/apis/jaegertracing/v1/builder.go 0% <0%> (ø) ⬆️
pkg/inventory/secret.go 100% <100%> (ø) ⬆️
pkg/inventory/deployment.go 100% <100%> (ø) ⬆️
pkg/inventory/account.go 100% <100%> (ø) ⬆️
pkg/controller/jaeger/account.go 74.19% <100%> (+10.55%) ⬆️
pkg/inventory/ingress.go 100% <100%> (ø) ⬆️
pkg/inventory/configmap.go 100% <100%> (ø) ⬆️
pkg/controller/jaeger/service.go 74.19% <100%> (+10.55%) ⬆️
pkg/inventory/daemonset.go 100% <100%> (ø) ⬆️
pkg/controller/jaeger/elasticsearch.go 56.41% <100%> (+5.68%) ⬆️
... and 11 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c802a91...72ab993. Read the comment docs.

@jkandasa
Copy link
Member

@jpkrohling can you provide a docker image for this PR?

pkg/controller/jaeger/deployment_test.go Outdated Show resolved Hide resolved
pkg/controller/jaeger/elasticsearch_test.go Outdated Show resolved Hide resolved
pkg/inventory/account_test.go Outdated Show resolved Hide resolved
pkg/inventory/configmap_test.go Outdated Show resolved Hide resolved
Signed-off-by: Juraci Paixão Kröhling <juraci@kroehling.de>
@jpkrohling jpkrohling merged commit d6204bc into jaegertracing:master Jul 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to create jaeger with the same name in different namespace
3 participants