-
Notifications
You must be signed in to change notification settings - Fork 344
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
Preserve generated cookie secret on the reconciliation process #883
Conversation
pkg/inject/oauth_proxy.go
Outdated
containerLoop: | ||
for index, container := range specSrc.Template.Spec.Containers { | ||
if container.Name == "oauth-proxy" { | ||
for argIndex, arg := range container.Args { |
There was a problem hiding this comment.
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:
jaeger-operator/pkg/util/util.go
Lines 169 to 177 in d169d79
func FindItem(prefix string, args []string) string { | |
for _, v := range args { | |
if strings.HasPrefix(v, prefix) { | |
return v | |
} | |
} | |
return "" | |
} |
pkg/inject/oauth_proxy.go
Outdated
destinationLoop: | ||
for index, container := range specDst.Template.Spec.Containers { | ||
if container.Name == "oauth-proxy" { | ||
for argIndex, arg := range container.Args { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
pkg/inject/oauth_proxy.go
Outdated
@@ -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) { |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
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:
|
I ran the full set of E2E tests on this on OCP 4.2 and they all passed. |
d47b7ac
to
33108b6
Compare
I've already address comments. If no other comment or observation I think this is ready to merge. |
There was a problem hiding this 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.
pkg/inventory/deployment.go
Outdated
@@ -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) |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
f6852d5
to
a074fff
Compare
There was a problem hiding this 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.
pkg/inject/oauth_proxy.go
Outdated
break | ||
} | ||
} | ||
// Found the cooke secretArg parameter, replace argument. |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
Done with observations. |
f62c5d4
to
673246d
Compare
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>
673246d
to
c044c13
Compare
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