Skip to content

Commit

Permalink
fix on MustUpdatePods behaviour with Secret vars
Browse files Browse the repository at this point in the history
  • Loading branch information
henrod committed Aug 30, 2017
1 parent 4894533 commit c67a163
Show file tree
Hide file tree
Showing 5 changed files with 192 additions and 8 deletions.
182 changes: 182 additions & 0 deletions controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1803,6 +1803,188 @@ cmd:
Expect(err).NotTo(HaveOccurred())
Expect(controller.MustUpdatePods(configYaml1, &configYaml2)).To(BeFalse())
})

It("should return true if secret vars change", func() {
yaml1 := `
name: controller-name
game: controller
image: controller/controller:v123
affinity: maestro-dedicated
toleration: maestro
ports:
- containerPort: 1235
protocol: UDP
name: port1
- containerPort: 7654
protocol: TCP
name: port2
limits:
memory: "66Mi"
cpu: "2"
shutdownTimeout: 20
autoscaling:
min: 3
up:
delta: 2
trigger:
usage: 60
time: 100
cooldown: 200
down:
delta: 1
trigger:
usage: 30
time: 500
cooldown: 500
env:
- name: MY_SECRET_ENV_VAR
valueFrom:
secretKeyRef:
name: secretname
value: secretkey
cmd:
- "./room"
`
yaml2 := `
name: controller-name
game: controller
image: controller/controller:v123
affinity: maestro-dedicated
toleration: maestro
ports:
- containerPort: 1235
protocol: UDP
name: port1
- containerPort: 7654
protocol: TCP
name: port2
limits:
memory: "66Mi"
cpu: "2"
shutdownTimeout: 20
autoscaling:
min: 3
up:
delta: 2
trigger:
usage: 60
time: 100
cooldown: 200
down:
delta: 1
trigger:
usage: 30
time: 500
cooldown: 500
env:
- name: MY_SECRET_ENV_VAR
valueFrom:
secretKeyRef:
name: newsecretname
value: newsecretkey
cmd:
- "./room"
`

var configYaml1 models.ConfigYAML
err := yaml.Unmarshal([]byte(yaml1), &configYaml1)
Expect(err).NotTo(HaveOccurred())
var configYaml2 models.ConfigYAML
err = yaml.Unmarshal([]byte(yaml2), &configYaml2)
Expect(err).NotTo(HaveOccurred())
Expect(controller.MustUpdatePods(&configYaml1, &configYaml2)).To(BeTrue())
})

It("should return false if min changes with secret vars", func() {
yaml1 := `
name: controller-name
game: controller
image: controller/controller:v123
affinity: maestro-dedicated
toleration: maestro
ports:
- containerPort: 1235
protocol: UDP
name: port1
- containerPort: 7654
protocol: TCP
name: port2
limits:
memory: "66Mi"
cpu: "2"
shutdownTimeout: 20
autoscaling:
min: 3
up:
delta: 2
trigger:
usage: 60
time: 100
cooldown: 200
down:
delta: 1
trigger:
usage: 30
time: 500
cooldown: 500
env:
- name: MY_SECRET_ENV_VAR
valueFrom:
secretKeyRef:
name: secretname
value: secretkey
cmd:
- "./room"
`
yaml2 := `
name: controller-name
game: controller
image: controller/controller:v123
affinity: maestro-dedicated
toleration: maestro
ports:
- containerPort: 1235
protocol: UDP
name: port1
- containerPort: 7654
protocol: TCP
name: port2
limits:
memory: "66Mi"
cpu: "2"
shutdownTimeout: 20
autoscaling:
min: 10
up:
delta: 2
trigger:
usage: 60
time: 100
cooldown: 200
down:
delta: 1
trigger:
usage: 30
time: 500
cooldown: 500
env:
- name: MY_SECRET_ENV_VAR
valueFrom:
secretKeyRef:
name: secretname
value: secretkey
cmd:
- "./room"
`

var configYaml1 models.ConfigYAML
err := yaml.Unmarshal([]byte(yaml1), &configYaml1)
Expect(err).NotTo(HaveOccurred())
var configYaml2 models.ConfigYAML
err = yaml.Unmarshal([]byte(yaml2), &configYaml2)
Expect(err).NotTo(HaveOccurred())
Expect(controller.MustUpdatePods(&configYaml1, &configYaml2)).To(BeFalse())
})
})

Describe("UpdateSchedulerConfig", func() {
Expand Down
2 changes: 1 addition & 1 deletion helm/charts/maestro/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: maestro
home: https://github.com/topfreegames/maestro
description: Maestro api and worker
version: 3.6.3
version: 3.6.4
maintainers:
- name: TFGCo
email: backend@tfgco.com
2 changes: 1 addition & 1 deletion metadata/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
package metadata

//Version of Maestro
var Version = "3.6.3"
var Version = "3.6.4"

//KubeVersion is the desired Kubernetes version
var KubeVersion = "v1.7.0"
4 changes: 2 additions & 2 deletions models/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@ var _ = Describe("Pod", func() {
},
{
Name: "SECRET_ENV_VAR",
ValueFrom: &models.ValueFrom{
SecretKeyRef: &models.SecretKeyRef{
ValueFrom: models.ValueFrom{
SecretKeyRef: models.SecretKeyRef{
Name: "my-secret",
Key: "secret-env-var",
},
Expand Down
10 changes: 6 additions & 4 deletions models/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,17 @@ type Resources struct {
}

// EnvVar has name and value of an environment variable
// Obs.: ValueFrom must not be a pointer so it can compare at controller.go MustUpdate function
type EnvVar struct {
Name string `yaml:"name" json:"name"`
Value string `yaml:"value" json:"value"`
ValueFrom *ValueFrom `yaml:"valueFrom" json:"valueFrom"`
Name string `yaml:"name" json:"name"`
Value string `yaml:"value" json:"value"`
ValueFrom ValueFrom `yaml:"valueFrom" json:"valueFrom"`
}

// ValueFrom has environment variables from secrets
// Obs.: ValueFrom must not be a pointer so it can compare at controller.go MustUpdate function
type ValueFrom struct {
SecretKeyRef *SecretKeyRef `yaml:"secretKeyRef" json:"secretKeyRef"`
SecretKeyRef SecretKeyRef `yaml:"secretKeyRef" json:"secretKeyRef"`
}

// ValueFrom has environment variables from secrets
Expand Down

0 comments on commit c67a163

Please sign in to comment.