Skip to content

Commit

Permalink
Address requested changes
Browse files Browse the repository at this point in the history
Signed-off-by: Ruben Vargas <ruben.vp8510@gmail.com>
  • Loading branch information
rubenvp8510 committed Feb 4, 2020
1 parent a7a5df8 commit d47b7ac
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
38 changes: 14 additions & 24 deletions pkg/inject/oauth_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package inject
import (
"fmt"
"sort"
"strings"

"github.com/spf13/viper"
appsv1 "k8s.io/api/apps/v1"
Expand Down Expand Up @@ -99,34 +98,25 @@ func getOAuthProxyContainer(jaeger *v1.Jaeger) corev1.Container {
}
}

//PreserveOauthCookieSecret preserve the generated oauth cookie across multiple reconciliations
func PreserveOauthCookieSecret(specSrc, specDst *appsv1.DeploymentSpec) {
secret := ""
// Find secret from old object
containerLoop:
for index, container := range specSrc.Template.Spec.Containers {
//PropagateOAuthCookieSecret preserve the generated oauth cookie across multiple reconciliations
func PropagateOAuthCookieSecret(specSrc, specDst *appsv1.DeploymentSpec) appsv1.DeploymentSpec {
spec := specDst.DeepCopy()
secretArg := ""
// Find secretArg from old object
for _, container := range specSrc.Template.Spec.Containers {
if container.Name == "oauth-proxy" {
for argIndex, arg := range container.Args {
if strings.HasPrefix(arg, "--cookie-secret=") {
secret = specSrc.Template.Spec.Containers[index].Args[argIndex]
break containerLoop
}
}
secretArg = util.FindItem("--cookie-secret=", container.Args)
break
}
}

// Found the cooke secret parameter.
if secret != "" {
destinationLoop:
for index, container := range specDst.Template.Spec.Containers {
// Found the cooke secretArg parameter, replace argument.
if secretArg != "" {
for i, container := range spec.Template.Spec.Containers {
if container.Name == "oauth-proxy" {
for argIndex, arg := range container.Args {
if strings.HasPrefix(arg, "--cookie-secret=") {
specDst.Template.Spec.Containers[index].Args[argIndex] = secret
break destinationLoop
}
}
util.ReplaceArgument("--cookie-secret", secretArg, spec.Template.Spec.Containers[i].Args)
}
}
}

return *spec
}
2 changes: 1 addition & 1 deletion pkg/inventory/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +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
inject.PreserveOauthCookieSecret(&t.Spec, &tp.Spec)
tp.Spec = inject.PropagateOAuthCookieSecret(&t.Spec, &tp.Spec)
tp.ObjectMeta.OwnerReferences = v.ObjectMeta.OwnerReferences

for k, v := range v.ObjectMeta.Annotations {
Expand Down
10 changes: 10 additions & 0 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
if strings.HasPrefix(arg, prefix) {
args[argIndex] = newValue
return
}
}
}

// GetPort returns a port, either from supplied default port, or extracted from supplied arg value
func GetPort(arg string, args []string, port int32) int32 {
portArg := FindItem(arg, args)
Expand Down

0 comments on commit d47b7ac

Please sign in to comment.