-
Notifications
You must be signed in to change notification settings - Fork 742
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #433 from weaveworks/projected-configs
Track projected configmaps and secrets
- Loading branch information
Showing
4 changed files
with
277 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
package canary | ||
|
||
import ( | ||
"testing" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func TestConfigTracker_ConfigMaps(t *testing.T) { | ||
mocks := newFixture() | ||
configMap := newTestConfigMap() | ||
configMapProjected := newTestConfigProjected() | ||
|
||
err := mocks.deployer.Initialize(mocks.canary, true) | ||
if err != nil { | ||
t.Fatal(err.Error()) | ||
} | ||
|
||
depPrimary, err := mocks.kubeClient.AppsV1().Deployments("default").Get("podinfo-primary", metav1.GetOptions{}) | ||
if err != nil { | ||
t.Fatal(err.Error()) | ||
} | ||
|
||
configPrimaryVolName := depPrimary.Spec.Template.Spec.Volumes[0].VolumeSource.ConfigMap.LocalObjectReference.Name | ||
if configPrimaryVolName != "podinfo-config-vol-primary" { | ||
t.Errorf("Got config name %v wanted %v", configPrimaryVolName, "podinfo-config-vol-primary") | ||
} | ||
|
||
configPrimary, err := mocks.kubeClient.CoreV1().ConfigMaps("default").Get("podinfo-config-env-primary", metav1.GetOptions{}) | ||
if err != nil { | ||
t.Fatal(err.Error()) | ||
} | ||
|
||
if configPrimary.Data["color"] != configMap.Data["color"] { | ||
t.Errorf("Got ConfigMap color %s wanted %s", configPrimary.Data["color"], configMap.Data["color"]) | ||
} | ||
|
||
configPrimaryEnv, err := mocks.kubeClient.CoreV1().ConfigMaps("default").Get("podinfo-config-all-env-primary", metav1.GetOptions{}) | ||
if err != nil { | ||
t.Fatal(err.Error()) | ||
} | ||
|
||
if configPrimaryEnv.Data["color"] != configMap.Data["color"] { | ||
t.Errorf("Got ConfigMap %s wanted %s", configPrimaryEnv.Data["a"], configMap.Data["color"]) | ||
} | ||
|
||
configPrimaryVol, err := mocks.kubeClient.CoreV1().ConfigMaps("default").Get("podinfo-config-vol-primary", metav1.GetOptions{}) | ||
if err != nil { | ||
t.Fatal(err.Error()) | ||
} | ||
|
||
if configPrimaryVol.Data["color"] != configMap.Data["color"] { | ||
t.Errorf("Got ConfigMap color %s wanted %s", configPrimary.Data["color"], configMap.Data["color"]) | ||
} | ||
|
||
configProjectedName := depPrimary.Spec.Template.Spec.Volumes[2].VolumeSource.Projected.Sources[0].ConfigMap.Name | ||
if configProjectedName != "podinfo-config-projected-primary" { | ||
t.Errorf("Got config name %v wanted %v", configProjectedName, "podinfo-config-projected-primary") | ||
} | ||
|
||
configPrimaryProjected, err := mocks.kubeClient.CoreV1().ConfigMaps("default").Get("podinfo-config-vol-primary", metav1.GetOptions{}) | ||
if err != nil { | ||
t.Fatal(err.Error()) | ||
} | ||
|
||
if configPrimaryProjected.Data["color"] != configMapProjected.Data["color"] { | ||
t.Errorf("Got ConfigMap color %s wanted %s", configPrimaryProjected.Data["color"], configMapProjected.Data["color"]) | ||
} | ||
} | ||
|
||
func TestConfigTracker_Secrets(t *testing.T) { | ||
mocks := newFixture() | ||
secret := newTestSecret() | ||
secretProjected := newTestSecretProjected() | ||
|
||
err := mocks.deployer.Initialize(mocks.canary, true) | ||
if err != nil { | ||
t.Fatal(err.Error()) | ||
} | ||
|
||
depPrimary, err := mocks.kubeClient.AppsV1().Deployments("default").Get("podinfo-primary", metav1.GetOptions{}) | ||
if err != nil { | ||
t.Fatal(err.Error()) | ||
} | ||
|
||
secretPrimaryVolName := depPrimary.Spec.Template.Spec.Volumes[1].VolumeSource.Secret.SecretName | ||
if secretPrimaryVolName != "podinfo-secret-vol-primary" { | ||
t.Errorf("Got config name %v wanted %v", secretPrimaryVolName, "podinfo-secret-vol-primary") | ||
} | ||
|
||
secretPrimary, err := mocks.kubeClient.CoreV1().Secrets("default").Get("podinfo-secret-env-primary", metav1.GetOptions{}) | ||
if err != nil { | ||
t.Fatal(err.Error()) | ||
} | ||
|
||
if string(secretPrimary.Data["apiKey"]) != string(secret.Data["apiKey"]) { | ||
t.Errorf("Got primary secret %s wanted %s", secretPrimary.Data["apiKey"], secret.Data["apiKey"]) | ||
} | ||
|
||
secretPrimaryEnv, err := mocks.kubeClient.CoreV1().Secrets("default").Get("podinfo-secret-all-env-primary", metav1.GetOptions{}) | ||
if err != nil { | ||
t.Fatal(err.Error()) | ||
} | ||
|
||
if string(secretPrimaryEnv.Data["apiKey"]) != string(secret.Data["apiKey"]) { | ||
t.Errorf("Got primary secret %s wanted %s", secretPrimary.Data["apiKey"], secret.Data["apiKey"]) | ||
} | ||
|
||
secretPrimaryVol, err := mocks.kubeClient.CoreV1().Secrets("default").Get("podinfo-secret-vol-primary", metav1.GetOptions{}) | ||
if err != nil { | ||
t.Fatal(err.Error()) | ||
} | ||
|
||
if string(secretPrimaryVol.Data["apiKey"]) != string(secret.Data["apiKey"]) { | ||
t.Errorf("Got primary secret %s wanted %s", secretPrimary.Data["apiKey"], secret.Data["apiKey"]) | ||
} | ||
|
||
secretProjectedName := depPrimary.Spec.Template.Spec.Volumes[2].VolumeSource.Projected.Sources[1].Secret.Name | ||
if secretProjectedName != "podinfo-secret-projected-primary" { | ||
t.Errorf("Got config name %v wanted %v", secretProjectedName, "podinfo-secret-projected-primary") | ||
} | ||
|
||
secretPrimaryProjected, err := mocks.kubeClient.CoreV1().Secrets("default").Get("podinfo-secret-projected-primary", metav1.GetOptions{}) | ||
if err != nil { | ||
t.Fatal(err.Error()) | ||
} | ||
|
||
if string(secretPrimaryProjected.Data["apiKey"]) != string(secretProjected.Data["apiKey"]) { | ||
t.Errorf("Got primary secret %s wanted %s", secretPrimaryProjected.Data["apiKey"], secretProjected.Data["apiKey"]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.