Skip to content

Commit

Permalink
Merge pull request crossplane#269 from silotrd/master
Browse files Browse the repository at this point in the history
[ISSUE crossplane#264] Bug fixed, should not pass annotations into podTemplate
  • Loading branch information
wonderflow authored Oct 27, 2020
2 parents 696eb7b + d26cc36 commit ad311db
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@ func TestRenderDeployment(t *testing.T) {
t.Errorf("\nReason: %s\ncontainerizedWorkloadTranslator(...): -want, +got:\n%s", "pass label", diff)
}

if diff := cmp.Diff(dmAnnotation, deploy.Spec.Template.GetAnnotations()); diff != "" {
t.Errorf("\nReason: %s\ncontainerizedWorkloadTranslator(...): -want, +got:\n%s", "pass annotation", diff)
}

if len(deploy.GetOwnerReferences()) != 1 {
t.Errorf("deplyment should have one owner reference")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ func TranslateContainerWorkload(ctx context.Context, w oam.Workload) ([]oam.Obje

// pass through label and annotation from the workload to the deployment
util.PassLabelAndAnnotation(w, d)
// pass through label and annotation from the workload to the pod template too
util.PassLabelAndAnnotation(w, &d.Spec.Template)
// pass through label from the workload to the pod template
util.PassLabel(w, &d.Spec.Template)

return []oam.Object{d}, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ func dmWithLabel(label map[string]string) deploymentModifier {
func dmWithAnnotation(annotation map[string]string) deploymentModifier {
return func(cw *appsv1.Deployment) {
cw.Annotations = annotation
cw.Spec.Template.Annotations = annotation
}
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/oam/util/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,12 @@ type labelAnnotationObject interface {
SetAnnotations(annotations map[string]string)
}

// PassLabel passes through labels from the parent to the child object
func PassLabel(parentObj oam.Object, childObj labelAnnotationObject) {
// pass app-config labels
childObj.SetLabels(MergeMap(parentObj.GetLabels(), childObj.GetLabels()))
}

// PassLabelAndAnnotation passes through labels and annotation objectMeta from the parent to the child object
func PassLabelAndAnnotation(parentObj oam.Object, childObj labelAnnotationObject) {
// pass app-config labels
Expand Down
24 changes: 19 additions & 5 deletions test/e2e-test/containerized_workload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ import (

var _ = Describe("ContainerizedWorkload", func() {
ctx := context.TODO()
var namespace, fakeLabelKey, componentName, workloadInstanceName, imageName string
var namespace, fakeLabelKey, fakeAnnotationKey, componentName, workloadInstanceName, imageName string
var replica int32
var ns corev1.Namespace
var wd v1alpha2.WorkloadDefinition
var label map[string]string
var annotations map[string]string
var wl v1alpha2.ContainerizedWorkload
var comp v1alpha2.Component
var appConfig v1alpha2.ApplicationConfiguration
Expand All @@ -37,6 +38,7 @@ var _ = Describe("ContainerizedWorkload", func() {
// init the strings
namespace = "containerized-workload-test"
fakeLabelKey = "workload"
fakeAnnotationKey = "kubectl.kubernetes.io/last-applied-configuration"
componentName = "example-component"
workloadInstanceName = "example-appconfig-workload"
imageName = "wordpress:php7.2"
Expand Down Expand Up @@ -159,11 +161,13 @@ var _ = Describe("ContainerizedWorkload", func() {
// Create application configuration
workloadInstanceName := "example-appconfig-workload"
imageName := "wordpress:php7.2"
annotations = map[string]string{fakeAnnotationKey: "fake-annotation-key-item"}
appConfig = v1alpha2.ApplicationConfiguration{
ObjectMeta: metav1.ObjectMeta{
Name: "example-appconfig",
Namespace: namespace,
Labels: label,
Name: "example-appconfig",
Namespace: namespace,
Labels: label,
Annotations: annotations,
},
Spec: v1alpha2.ApplicationConfigurationSpec{
Components: []v1alpha2.ApplicationConfigurationComponent{
Expand Down Expand Up @@ -268,7 +272,17 @@ var _ = Describe("ContainerizedWorkload", func() {
},
time.Second*60, time.Second*5).Should(BeEquivalentTo(replica))
Expect(*deploy.Spec.Replicas).Should(BeEquivalentTo(replica))

By("Verify pod annotations should not contain kubectl.kubernetes.io/last-applied-configuration")
Eventually(
func() bool {
k8sClient.Get(ctx, objectKey, deploy)
annotations := deploy.Spec.Template.Annotations
if _, ok := annotations[fakeAnnotationKey]; ok {
return false
}
return true
},
time.Second*15, time.Millisecond*500).Should(BeTrue())
})

It("checking appConfig status changed outside of the controller loop is preserved", func() {
Expand Down

0 comments on commit ad311db

Please sign in to comment.