Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Certificates with Ingress annotations #6567

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 8 additions & 6 deletions pkg/controller/certificate-shim/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,14 +431,12 @@ func buildCertificates(

updateCrt := existingCrt.DeepCopy()

updateCrt.Spec = crt.Spec
updateCrt.Annotations = crt.Annotations
updateCrt.Labels = crt.Labels

setIssuerSpecificConfig(crt, ingLike)
updateCrt.Spec = crt.Spec

updateCrts = append(updateCrts, updateCrt)
} else {

newCrts = append(newCrts, crt)
}
}
Expand Down Expand Up @@ -489,9 +487,13 @@ func certNeedsUpdate(a, b *cmapi.Certificate) bool {
}

// TODO: we may need to allow users to edit the managed Certificate resources
// to add their own labels directly.
// Right now, we'll reset/remove the label values back automatically.
// to add their own annotations and labels directly.
// Right now, we'll reset/remove the annotation and label values back automatically.
// Let's hope no other controllers do this automatically, else we'll start fighting...
if !reflect.DeepEqual(a.Annotations, b.Annotations) {
return true
}

if !reflect.DeepEqual(a.Labels, b.Labels) {
return true
}
Expand Down
73 changes: 73 additions & 0 deletions pkg/controller/certificate-shim/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,79 @@ func Test_hasShimAnnotation(t *testing.T) {
})
}

func Test_certNeedsUpdate(t *testing.T) {
type testT struct {
CertA *cmapi.Certificate
CertB *cmapi.Certificate
Want bool
}

t.Run("ingress", func(t *testing.T) {
tests := []testT{
{
CertA: &cmapi.Certificate{
ObjectMeta: metav1.ObjectMeta{
Name: "example-com-tls",
Namespace: gen.DefaultTestNamespace,
},
},
CertB: &cmapi.Certificate{
ObjectMeta: metav1.ObjectMeta{
Name: "example-com-tls",
Namespace: gen.DefaultTestNamespace,
},
},
Want: false,
},
{
CertA: &cmapi.Certificate{
ObjectMeta: metav1.ObjectMeta{
Name: "example-com-tls",
Namespace: gen.DefaultTestNamespace,
Labels: map[string]string{
"changing-label": "will be updated",
},
},
},
CertB: &cmapi.Certificate{
ObjectMeta: metav1.ObjectMeta{
Name: "example-com-tls",
Namespace: gen.DefaultTestNamespace,
Labels: map[string]string{
"changing-label": "is updated",
},
},
},
Want: true,
},
{
CertA: &cmapi.Certificate{
ObjectMeta: metav1.ObjectMeta{
Name: "example-com-tls",
Namespace: gen.DefaultTestNamespace,
},
},
CertB: &cmapi.Certificate{
ObjectMeta: metav1.ObjectMeta{
Name: "example-com-tls",
Namespace: gen.DefaultTestNamespace,
Annotations: map[string]string{
cmapi.IngressACMEIssuerHTTP01IngressClassAnnotationKey: "nginx",
},
},
},
Want: true,
},
}
for _, test := range tests {
certNeedsUpdate := certNeedsUpdate(test.CertA, test.CertB)
if certNeedsUpdate != test.Want {
t.Errorf("Expected certNeedsUpdate=%v for certificates \n%#v\nand\n%#v", test.Want, test.CertA, test.CertB)
}
}
})
}

func TestSync(t *testing.T) {
clusterIssuer := gen.ClusterIssuer("issuer-name")
acmeIssuerNewFormat := gen.Issuer("issuer-name",
Expand Down