Skip to content

Commit

Permalink
Merge pull request #10368 from k8s-infra-cherrypick-robot/cherry-pick…
Browse files Browse the repository at this point in the history
…-10321-to-release-1.7

[release-1.7] 🐛 Checking cert's keypair for nil before accessing to avoid panics
  • Loading branch information
k8s-ci-robot committed Apr 3, 2024
2 parents 6774f33 + 6d55c7c commit c7ee120
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions util/secret/certificates.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,10 @@ func (c *Certificate) AsSecret(clusterName client.ObjectKey, owner metav1.OwnerR
// AsFiles converts the certificate to a slice of Files that may have 0, 1 or 2 Files.
func (c *Certificate) AsFiles() []bootstrapv1.File {
out := make([]bootstrapv1.File, 0)
if c.KeyPair == nil {
return out
}

if len(c.KeyPair.Cert) > 0 {
out = append(out, bootstrapv1.File{
Path: c.CertFile,
Expand Down
8 changes: 8 additions & 0 deletions util/secret/certificates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,11 @@ func TestNewControlPlaneJoinCertsExternal(t *testing.T) {
certs := secret.NewControlPlaneJoinCerts(config)
g.Expect(certs.GetByPurpose(secret.EtcdCA).KeyFile).To(BeEmpty())
}

func TestNewControlPlaneJoinCertsAsFilesNotPanicsWhenEmpty(t *testing.T) {
g := NewWithT(t)

config := &bootstrapv1.ClusterConfiguration{}
certs := secret.NewControlPlaneJoinCerts(config)
g.Expect(certs.AsFiles()).To(BeEmpty())
}

0 comments on commit c7ee120

Please sign in to comment.