#38 Omit KUBERNETES_* envs in containers
This commit is contained in:
parent
6f1b133741
commit
42dc5569c5
|
|
@ -510,7 +510,7 @@ func (r *ReconcileJenkinsBaseConfiguration) compareContainers(expected corev1.Co
|
|||
r.logger.Info(fmt.Sprintf("Command has changed to '%+v' in container '%s', recreating pod", expected.Command, expected.Name))
|
||||
return true
|
||||
}
|
||||
if !reflect.DeepEqual(expected.Env, actual.Env) {
|
||||
if !compareEnv(expected.Env, actual.Env) {
|
||||
r.logger.Info(fmt.Sprintf("Env has changed to '%+v' in container '%s', recreating pod", expected.Env, expected.Name))
|
||||
return true
|
||||
}
|
||||
|
|
@ -562,6 +562,18 @@ func (r *ReconcileJenkinsBaseConfiguration) compareContainers(expected corev1.Co
|
|||
return false
|
||||
}
|
||||
|
||||
func compareEnv(expected, actual []corev1.EnvVar) bool {
|
||||
var actualEnv []corev1.EnvVar
|
||||
for _, env := range actual {
|
||||
if env.Name == "KUBERNETES_PORT_443_TCP_ADDR" || env.Name == "KUBERNETES_PORT" ||
|
||||
env.Name == "KUBERNETES_PORT_443_TCP" || env.Name == "KUBERNETES_SERVICE_HOST" {
|
||||
continue
|
||||
}
|
||||
actualEnv = append(actualEnv, env)
|
||||
}
|
||||
return reflect.DeepEqual(expected, actualEnv)
|
||||
}
|
||||
|
||||
// CompareContainerVolumeMounts returns true if two containers volume mounts are the same
|
||||
func CompareContainerVolumeMounts(expected corev1.Container, actual corev1.Container) bool {
|
||||
var withoutServiceAccount []corev1.VolumeMount
|
||||
|
|
|
|||
|
|
@ -414,3 +414,84 @@ func TestReconcileJenkinsBaseConfiguration_verifyPlugins(t *testing.T) {
|
|||
assert.False(t, got)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_compareEnv(t *testing.T) {
|
||||
t.Run("empty", func(t *testing.T) {
|
||||
var expected []corev1.EnvVar
|
||||
var actual []corev1.EnvVar
|
||||
|
||||
got := compareEnv(expected, actual)
|
||||
|
||||
assert.True(t, got)
|
||||
})
|
||||
t.Run("same", func(t *testing.T) {
|
||||
expected := []corev1.EnvVar{
|
||||
{
|
||||
Name: "name",
|
||||
Value: "value",
|
||||
},
|
||||
}
|
||||
actual := []corev1.EnvVar{
|
||||
{
|
||||
Name: "name",
|
||||
Value: "value",
|
||||
},
|
||||
}
|
||||
|
||||
got := compareEnv(expected, actual)
|
||||
|
||||
assert.True(t, got)
|
||||
})
|
||||
t.Run("with KUBERNETES envs", func(t *testing.T) {
|
||||
expected := []corev1.EnvVar{
|
||||
{
|
||||
Name: "name",
|
||||
Value: "value",
|
||||
},
|
||||
}
|
||||
actual := []corev1.EnvVar{
|
||||
{
|
||||
Name: "name",
|
||||
Value: "value",
|
||||
},
|
||||
{
|
||||
Name: "KUBERNETES_PORT_443_TCP_ADDR",
|
||||
Value: "KUBERNETES_PORT_443_TCP_ADDR",
|
||||
},
|
||||
{
|
||||
Name: "KUBERNETES_PORT",
|
||||
Value: "KUBERNETES_PORT",
|
||||
},
|
||||
{
|
||||
Name: "KUBERNETES_PORT_443_TCP",
|
||||
Value: "KUBERNETES_PORT_443_TCP",
|
||||
},
|
||||
{
|
||||
Name: "KUBERNETES_SERVICE_HOST",
|
||||
Value: "KUBERNETES_SERVICE_HOST",
|
||||
},
|
||||
}
|
||||
|
||||
got := compareEnv(expected, actual)
|
||||
|
||||
assert.True(t, got)
|
||||
})
|
||||
t.Run("different", func(t *testing.T) {
|
||||
expected := []corev1.EnvVar{
|
||||
{
|
||||
Name: "name",
|
||||
Value: "value",
|
||||
},
|
||||
}
|
||||
actual := []corev1.EnvVar{
|
||||
{
|
||||
Name: "name2",
|
||||
Value: "value2",
|
||||
},
|
||||
}
|
||||
|
||||
got := compareEnv(expected, actual)
|
||||
|
||||
assert.False(t, got)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue