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

Preserve generated cookie secret on the reconciliation process #883

Merged

Conversation

rubenvp8510
Copy link
Collaborator

@rubenvp8510 rubenvp8510 commented Feb 4, 2020

This is another patch for prevent multiple creations of deployments when a jaeger resource is created.

// cc: @kevinearls

I only tested with all-in-one strategy, I'll test tomorrow with-cassandra yaml file

containerLoop:
for index, container := range specSrc.Template.Spec.Containers {
if container.Name == "oauth-proxy" {
for argIndex, arg := range container.Args {
Copy link
Contributor

Choose a reason for hiding this comment

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

You can probably use something like this function:

func FindItem(prefix string, args []string) string {
for _, v := range args {
if strings.HasPrefix(v, prefix) {
return v
}
}
return ""
}

destinationLoop:
for index, container := range specDst.Template.Spec.Containers {
if container.Name == "oauth-proxy" {
for argIndex, arg := range container.Args {
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, use util.FindItem

Copy link
Collaborator Author

@rubenvp8510 rubenvp8510 Feb 4, 2020

Choose a reason for hiding this comment

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

I modified the above code to use util.FindItem, but here util.FindItem only return the value if found it, in this case I'm interested on modify the value. I don't want to modify util.FindItem to return index, as is used in other parts of the code.

@@ -97,3 +98,35 @@ func getOAuthProxyContainer(jaeger *v1.Jaeger) corev1.Container {
Resources: commonSpec.Resources,
}
}

//PreserveOauthCookieSecret preserve the generated oauth cookie across multiple reconciliations
func PreserveOauthCookieSecret(specSrc, specDst *appsv1.DeploymentSpec) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This could have a better name. Perhaps PropagateOAuthCookieSecret? Or just HandleOAuthCookieSecret?

Copy link
Contributor

Choose a reason for hiding this comment

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

In recent changes, I've been trying to avoid those pointers, returning the resulting spec. You could also do it, so that your caller would look like this:

tp.Spec = inject.PropagateOAuthCookieSecret(&t.Spec, &tp.Spec)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sounds reasonable. I would prefer to not modify funcion parameters , make it pure function.

About the names, I'll rename it. I just put a the first name came to my mind just to test if this fix the issue.

Thanks.

@jpkrohling
Copy link
Contributor

By the way, the fix itself looks correct, as @kevinearls confirmed during his tests. I could also confirm that the several deployment versions were caused by this:

$ kubectl rollout history deployment/with-cassandra --revision=1 > /tmp/deployment-r1.yaml
$ kubectl rollout history deployment/with-cassandra --revision=2 > /tmp/deployment-r2.yaml
$ diff /tmp/deployment-r*
1c1
< deployment.extensions/with-cassandra with revision #1
---
> deployment.extensions/with-cassandra with revision #2
9c9
< 	pod-template-hash=59c7df5c79
---
> 	pod-template-hash=57865b948b
38c38
<       --cookie-secret=rcoiF6NixkQzKbhJFTJcEw==
---
>       --cookie-secret=yCD2nT9xw64DYqFKGxUYJw==

@kevinearls
Copy link
Contributor

I ran the full set of E2E tests on this on OCP 4.2 and they all passed.

@rubenvp8510
Copy link
Collaborator Author

I've already address comments. If no other comment or observation I think this is ready to merge.

Copy link
Contributor

@jpkrohling jpkrohling left a comment

Choose a reason for hiding this comment

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

Needs tests for the new util function, plus a small improvement can be made at the inventory routine. Other than that, LGTM.

@@ -28,6 +29,7 @@ func ForDeployments(existing []appsv1.Deployment, desired []appsv1.Deployment) D

// we can't blindly DeepCopyInto, so, we select what we bring from the new to the old object
tp.Spec = v.Spec
tp.Spec = inject.PropagateOAuthCookieSecret(&t.Spec, &tp.Spec)
Copy link
Contributor

Choose a reason for hiding this comment

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

You can have both lines 31 and 32 done on the same line:

tp.Spec = inject.PropagateOAuthCookieSecret(&t.Spec, v.Spec)

You'll need to change your arguments to accept values instead of pointers, which is in line with what we discussed in a previous review :)

@@ -176,6 +176,16 @@ func FindItem(prefix string, args []string) string {
return ""
}

// ReplaceArgument replace argument value with given value.
func ReplaceArgument(prefix string, newValue string, args []string) {
for argIndex, arg := range args {
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if prefix isn't found? And when multiple prefixes exist? You'll need tests to assert those cases.

This method could return a bool, signaling whether there was a replacement.

@rubenvp8510 rubenvp8510 force-pushed the cookie-secret-multiple-deps branch 3 times, most recently from f6852d5 to a074fff Compare February 6, 2020 07:04
Copy link
Contributor

@jpkrohling jpkrohling left a comment

Choose a reason for hiding this comment

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

Just a couple of minor comments, but LGTM in general.

break
}
}
// Found the cooke secretArg parameter, replace argument.
Copy link
Contributor

Choose a reason for hiding this comment

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

s/cooke/cookie

@@ -5,13 +5,15 @@ import (
"sort"
"testing"

v1 "github.com/jaegertracing/jaeger-operator/pkg/apis/jaegertracing/v1"
Copy link
Contributor

Choose a reason for hiding this comment

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

Something is odd with the formatter

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

mmm.. it is.

Not sure why but this happens when I do a make format.

Copy link
Collaborator Author

@rubenvp8510 rubenvp8510 Feb 6, 2020

Choose a reason for hiding this comment

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

I changed this line and make check don't pass. :(

pkg/util/util.go Outdated
@@ -176,6 +176,21 @@ func FindItem(prefix string, args []string) string {
return ""
}

// ReplaceArgument replace argument value with given value.
func ReplaceArgument(prefix string, newValue string, args []string, firstOccurrence bool) int {
Copy link
Contributor

Choose a reason for hiding this comment

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

I appreciate the idea behind the firstOccurrence, but there's no need for it, at least for the moment. If you decide to keep this type of feature, you can follow the idea behind Go's strings.Replace, where the last parameter is the max number of times the replace should be applied, with a negative meaning "replace all occurrences".

https://golang.org/src/strings/strings.go?s=23551:23597#L918

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll remove the feature, as you said is not necessary for now.

@rubenvp8510
Copy link
Collaborator Author

Done with observations.
Thanks

Signed-off-by: Ruben Vargas <ruben.vp8510@gmail.com>
Signed-off-by: Ruben Vargas <ruben.vp8510@gmail.com>
Signed-off-by: Ruben Vargas <ruben.vp8510@gmail.com>
Signed-off-by: Ruben Vargas <ruben.vp8510@gmail.com>
@jpkrohling jpkrohling merged commit f158ce5 into jaegertracing:master Feb 10, 2020
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.

3 participants