Skip to content

Commit

Permalink
test: add failing test
Browse files Browse the repository at this point in the history
Signed-off-by: Blake Pettersson <[email protected]>
  • Loading branch information
blakepettersson committed Sep 27, 2023
1 parent 2e5b8dd commit fb3d3ba
Show file tree
Hide file tree
Showing 4 changed files with 233 additions and 2 deletions.
33 changes: 31 additions & 2 deletions controller/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,6 @@ func TestNormalizeTargetResources(t *testing.T) {
require.True(t, ok)
assert.Equal(t, 2, len(containers))
})

t.Run("will correctly set array entries if new entries have been added", func(t *testing.T) {
// given
ignores := []v1alpha1.ResourceIgnoreDifferences{
Expand Down Expand Up @@ -431,7 +430,6 @@ func TestNormalizeTargetResources(t *testing.T) {
assert.Equal(t, "SOME_ENV_VAR", third.(map[string]interface{})["name"])
assert.Equal(t, "some_value", third.(map[string]interface{})["value"])
})

t.Run("mutating-webhook-config", func(t *testing.T) {
// given

Expand Down Expand Up @@ -467,6 +465,37 @@ func TestNormalizeTargetResources(t *testing.T) {
assert.Equal(t, "something", (second.(map[string]interface{})["clientConfig"]).(map[string]interface{})["caBundle"])
assert.Equal(t, "something-new", (third.(map[string]interface{})["clientConfig"]).(map[string]interface{})["caBundle"])
})
t.Run("rollout-obj", func(t *testing.T) {
// given

ignores := []v1alpha1.ResourceIgnoreDifferences{
{
Group: "argoproj.io",
Kind: "Rollout",
JQPathExpressions: []string{".spec.template.spec.containers[] | select(.name == \"init\") | .image"},
},
}
f := setup(t, ignores)
live := test.YamlToUnstructured(testdata.LiveRolloutYaml)
target := test.YamlToUnstructured(testdata.TargetRolloutYaml)
f.comparisonResult.reconciliationResult.Live = []*unstructured.Unstructured{live}
f.comparisonResult.reconciliationResult.Target = []*unstructured.Unstructured{target}

// when
targets, err := normalizeTargetResources(f.comparisonResult)

// then
require.NoError(t, err)
require.Equal(t, 1, len(targets))
containers, ok, err := unstructured.NestedSlice(targets[0].Object, "spec", "template", "spec", "containers")
require.NoError(t, err)
require.True(t, ok)
assert.Equal(t, 1, len(containers))

container := containers[0]

assert.Equal(t, int64(15), (container.(map[string]interface{})["livenessProbe"]).(map[string]interface{})["initialDelaySeconds"])
})
t.Run("ignore-deployment-image-replicas-changes-additive", func(t *testing.T) {
// given

Expand Down
6 changes: 6 additions & 0 deletions controller/testdata/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ var (
//go:embed target-mutating-webhook-config.yaml
TargetMutatingWebhookConfigYaml string

//go:embed live-rollout.yaml
LiveRolloutYaml string

//go:embed target-rollout.yaml
TargetRolloutYaml string

//go:embed target-deployment-new-entries.yaml
TargetDeploymentNewEntries string
)
122 changes: 122 additions & 0 deletions controller/testdata/live-rollout.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: >
{"apiVersion":"argoproj.io/v1alpha1","kind":"Rollout","metadata":{"annotations":{},"labels":{"app.kubernetes.io/component":"manual","app.kubernetes.io/instance":"init-manual","app.kubernetes.io/managed-by":"Helm","app.kubernetes.io/name":"init-manual","app.kubernetes.io/part-of":"init","helm.sh/chart":"init-0.1.0"},"name":"init-manual","namespace":"init"},"spec":{"replicas":1,"revisionHistoryLimit":4,"selector":{"matchLabels":{"app":"init-manual"}},"strategy":{"blueGreen":{"activeService":"manual","previewService":"manual-preview"}},"template":{"metadata":{"annotations":{"config.alpha.linkerd.io/proxy-wait-before-exit-seconds":"10","config.linkerd.io/proxy-await":"enabled","instrumentation.opentelemetry.io/container-names":"init","instrumentation.opentelemetry.io/inject-nodejs":"otel/init-instrumentation","linkerd.io/inject":"enabled"},"labels":{"app":"init-manual","linkerd.io/proxy-deployment":"init-manual"}},"spec":{"containers":[{"env":[{"name":"APP","value":"manual"},{"name":"HTTP_PORT","value":"8080"}],"image":"REDACTED","imagePullPolicy":"IfNotPresent","livenessProbe":{"failureThreshold":3,"grpc":{"port":8080,"service":"init"},"initialDelaySeconds":20,"periodSeconds":10},"name":"init","ports":[{"containerPort":8080,"protocol":"TCP"}],"readinessProbe":{"failureThreshold":1,"grpc":{"port":8080,"service":"init"},"initialDelaySeconds":20,"periodSeconds":5},"resources":{"limits":{"ephemeral-storage":"512Mi"},"requests":{"cpu":"50m","ephemeral-storage":"256Mi","memory":"256Mi"}}}],"imagePullSecrets":[{"name":"REDACTED"}],"nodeSelector":{"cloud.google.com/gke-provisioning":"spot","iam.gke.io/gke-metadata-server-enabled":"true"},"serviceAccountName":"default"}}}}
rollout.argoproj.io/revision: '215'
creationTimestamp: '2023-04-26T14:16:22Z'
generation: 228
labels:
app.kubernetes.io/component: manual
app.kubernetes.io/instance: init-manual
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: init-manual
app.kubernetes.io/part-of: init
helm.sh/chart: init-0.1.0
k8slens-edit-resource-version: v1alpha1
name: init-manual
namespace: init
resourceVersion: '97158718'
uid: ee833507-b862-47c4-ab1a-8c504ff1db71
spec:
replicas: 1
revisionHistoryLimit: 4
selector:
matchLabels:
app: init-manual
strategy:
blueGreen:
activeService: manual
previewService: manual-preview
template:
metadata:
annotations:
config.alpha.linkerd.io/proxy-wait-before-exit-seconds: '10'
config.linkerd.io/proxy-await: enabled
instrumentation.opentelemetry.io/container-names: init
instrumentation.opentelemetry.io/inject-nodejs: otel/init-instrumentation
linkerd.io/inject: enabled
labels:
app: init-manual
linkerd.io/proxy-deployment: init-manual
spec:
containers:
- env:
- name: APP
value: manual
- name: HTTP_PORT
value: '8080'
image: 'REDACTED'
imagePullPolicy: IfNotPresent
livenessProbe:
failureThreshold: 3
grpc:
port: 8080
service: init
initialDelaySeconds: 20
periodSeconds: 10
name: init
ports:
- containerPort: 8080
protocol: TCP
readinessProbe:
failureThreshold: 1
grpc:
port: 8080
service: init
initialDelaySeconds: 20
periodSeconds: 5
resources:
limits:
ephemeral-storage: 512Mi
requests:
cpu: 50m
ephemeral-storage: 256Mi
memory: 256Mi
imagePullSecrets:
- name: REDACTED
nodeSelector:
cloud.google.com/gke-provisioning: spot
iam.gke.io/gke-metadata-server-enabled: 'true'
serviceAccountName: default
status:
HPAReplicas: 1
availableReplicas: 1
blueGreen:
activeSelector: 6b6b5d8cd7
previewSelector: 6b6b5d8cd7
canary: {}
conditions:
- lastTransitionTime: '2023-08-30T09:45:41Z'
lastUpdateTime: '2023-08-30T09:45:41Z'
message: RolloutCompleted
reason: RolloutCompleted
status: 'True'
type: Completed
- lastTransitionTime: '2023-08-30T09:57:08Z'
lastUpdateTime: '2023-08-30T09:57:08Z'
message: Rollout is healthy
reason: RolloutHealthy
status: 'True'
type: Healthy
- lastTransitionTime: '2023-05-05T09:55:27Z'
lastUpdateTime: '2023-08-30T09:57:08Z'
message: ReplicaSet "init-manual-6b6b5d8cd7" has successfully progressed.
reason: NewReplicaSetAvailable
status: 'True'
type: Progressing
- lastTransitionTime: '2023-08-30T09:57:08Z'
lastUpdateTime: '2023-08-30T09:57:08Z'
message: Rollout has minimum availability
reason: AvailableReason
status: 'True'
type: Available
currentPodHash: 6b6b5d8cd7
observedGeneration: '228'
phase: Healthy
readyReplicas: 1
replicas: 1
selector: 'app=init-manual,rollouts-pod-template-hash=6b6b5d8cd7'
stableRS: 6b6b5d8cd7
updatedReplicas: 1
74 changes: 74 additions & 0 deletions controller/testdata/target-rollout.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
labels:
app.kubernetes.io/component: manual
app.kubernetes.io/instance: init-manual
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: init-manual
app.kubernetes.io/part-of: init
helm.sh/chart: init-0.1.0
k8slens-edit-resource-version: v1alpha1
name: init-manual
namespace: init
spec:
replicas: 1
revisionHistoryLimit: 4
selector:
matchLabels:
app: init-manual
strategy:
blueGreen:
activeService: manual
previewService: manual-preview
template:
metadata:
annotations:
config.alpha.linkerd.io/proxy-wait-before-exit-seconds: '10'
config.linkerd.io/proxy-await: enabled
instrumentation.opentelemetry.io/container-names: init
instrumentation.opentelemetry.io/inject-nodejs: otel/init-instrumentation
linkerd.io/inject: enabled
labels:
app: init-manual
linkerd.io/proxy-deployment: init-manual
spec:
containers:
- env:
- name: APP
value: manual
- name: HTTP_PORT
value: '8080'
image: 'REDACTED'
imagePullPolicy: IfNotPresent
livenessProbe:
failureThreshold: 3
grpc:
port: 8080
service: init
initialDelaySeconds: 15
periodSeconds: 10
name: init
ports:
- containerPort: 8080
protocol: TCP
readinessProbe:
failureThreshold: 1
grpc:
port: 8080
service: init
initialDelaySeconds: 20
periodSeconds: 5
resources:
limits:
ephemeral-storage: 512Mi
requests:
cpu: 50m
ephemeral-storage: 256Mi
memory: 256Mi
imagePullSecrets:
- name: REDACTED
nodeSelector:
cloud.google.com/gke-provisioning: spot
iam.gke.io/gke-metadata-server-enabled: 'true'
serviceAccountName: default

0 comments on commit fb3d3ba

Please sign in to comment.