Compare commits

...

6 Commits

Author SHA1 Message Date
Kubernetes Publisher
54601aa99f Update dependencies to v0.34.2 tag 2025-11-12 13:06:06 +00:00
Kubernetes Publisher
1bb1ad283d Merge pull request #134589 from liggitt/automated-cherry-pick-of-#134588-upstream-release-1.34
Automated cherry pick of #134588: go 1.25.2/1.24.8 related fixes

Kubernetes-commit: 00b6a4c7afdbd95d9ef5b5f3cada04ac15b0c135
2025-10-14 08:41:34 -07:00
Jordan Liggitt
2505205c42 Remove invalid SAN certificate construction
Kubernetes-commit: f40e4ce55298e0d0ea0149987e774b44a276075c
2025-10-09 16:27:05 -04:00
Kubernetes Publisher
7ffba0fd20 Merge pull request #134004 from DerekFrank/automated-cherry-pick-of-#133573-upstream-release-1.34
Automated cherry pick of #133573: fix: Update unit test to catch actual nil Labels case and fix functionality to handle nil Labels

Kubernetes-commit: a147a2c8da02ff628e560c32202de5951f296662
2025-09-26 05:16:16 -07:00
DerekFrank
145cb8f04b gofmt and review feedback
Kubernetes-commit: 4a40ddf1e6b6ec907a2875f0427e129de4bd789f
2025-08-18 09:52:15 -07:00
DerekFrank
ddcdc12cd6 fix: Update unit test to catch actual nil Labels case and fix functionality to handle nil Labels
Kubernetes-commit: 4ae3b64b73617c9f9f162874e87f500e265f05e1
2025-08-15 14:28:18 -07:00
5 changed files with 38 additions and 23 deletions

4
go.mod
View File

@@ -25,8 +25,8 @@ require (
golang.org/x/time v0.9.0
google.golang.org/protobuf v1.36.5
gopkg.in/evanphx/json-patch.v4 v4.12.0
k8s.io/api v0.0.0-20250816102306-133a39c86037
k8s.io/apimachinery v0.0.0-20250816075726-b72d93d17433
k8s.io/api v0.34.2
k8s.io/apimachinery v0.34.2
k8s.io/klog/v2 v2.130.1
k8s.io/kube-openapi v0.0.0-20250710124328-f3f2b991d03b
k8s.io/utils v0.0.0-20250604170112-4c0f3b243397

8
go.sum
View File

@@ -150,10 +150,10 @@ gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
k8s.io/api v0.0.0-20250816102306-133a39c86037 h1:1TkkwH4RQbgEyFSdRQhjRFsReRUNRkWX44PjdTHC7cQ=
k8s.io/api v0.0.0-20250816102306-133a39c86037/go.mod h1:lH4Pg8ye7aAjw/eEVA23Yix/PdEwoS/6mwXugx0o8zE=
k8s.io/apimachinery v0.0.0-20250816075726-b72d93d17433 h1:PnxBv2aVdRFKtBihDGvDmF/VpvunGK8oo2eNO0GjghE=
k8s.io/apimachinery v0.0.0-20250816075726-b72d93d17433/go.mod h1:/GwIlEcWuTX9zKIg2mbw0LRFIsXwrfoVxn+ef0X13lw=
k8s.io/api v0.34.2 h1:fsSUNZhV+bnL6Aqrp6O7lMTy6o5x2C4XLjnh//8SLYY=
k8s.io/api v0.34.2/go.mod h1:MMBPaWlED2a8w4RSeanD76f7opUoypY8TFYkSM+3XHw=
k8s.io/apimachinery v0.34.2 h1:zQ12Uk3eMHPxrsbUJgNF8bTauTVR2WgqJsTmwTE/NW4=
k8s.io/apimachinery v0.34.2/go.mod h1:/GwIlEcWuTX9zKIg2mbw0LRFIsXwrfoVxn+ef0X13lw=
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=
k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
k8s.io/kube-openapi v0.0.0-20250710124328-f3f2b991d03b h1:MloQ9/bdJyIu9lb1PzujOPolHyvO06MXG5TUIj2mNAA=

View File

@@ -77,6 +77,9 @@ func (ll *LeaseLock) Update(ctx context.Context, ler LeaderElectionRecord) error
ll.lease.Spec = LeaderElectionRecordToLeaseSpec(&ler)
if ll.Labels != nil {
if ll.lease.Labels == nil {
ll.lease.Labels = map[string]string{}
}
// Only overwrite the labels that are specifically set
for k, v := range ll.Labels {
ll.lease.Labels[k] = v

View File

@@ -266,7 +266,7 @@ func TestLeaseConversion(t *testing.T) {
}
}
func TestUpdateWithNilLabels(t *testing.T) {
func TestUpdateWithNilLabelsOnLease(t *testing.T) {
setup()
// Create initial lease
@@ -278,23 +278,33 @@ func TestUpdateWithNilLabels(t *testing.T) {
t.Fatalf("Failed to get lease: %v", err)
}
leaseLock.lease.Labels = nil
leaseLock.Labels = map[string]string{"custom-key": "custom-val"}
// Update should succeed even with nil Labels on the lease itself
if err := leaseLock.Update(context.Background(), testRecord); err != nil {
t.Errorf("Update failed with nil Labels: %v", err)
}
}
func TestUpdateWithNilLabelsOnLeaseLock(t *testing.T) {
setup()
// Create initial lease
if err := leaseLock.Create(context.Background(), testRecord); err != nil {
t.Fatalf("Failed to create lease: %v", err)
}
// Get the lease to initialize leaseLock.lease
if _, _, err := leaseLock.Get(context.Background()); err != nil {
t.Fatalf("Failed to get lease: %v", err)
}
leaseLock.Labels = nil
leaseLock.lease.Labels = map[string]string{"custom-key": "custom-val"}
// Update labels
lease, err := leaseLock.Client.Leases(testNamespace).Update(context.Background(), leaseLock.lease, metav1.UpdateOptions{})
if err != nil {
t.Fatalf("Failed to update lease labels: %v", err)
}
val, exists := lease.Labels["custom-key"]
if !exists {
t.Error("Label was overidden on the lease")
}
if val != "custom-val" {
t.Errorf("Label value mismatch, got %q want %q", val, "custom-val")
}
// Update should succeed even with nil Labels
// Update should succeed even with nil Labels on the leaselock
if err := leaseLock.Update(context.Background(), testRecord); err != nil {
t.Errorf("Update failed with nil Labels: %v", err)
}

View File

@@ -75,13 +75,15 @@ func NewSelfSignedCACert(cfg Config, key crypto.Signer) (*x509.Certificate, erro
CommonName: cfg.CommonName,
Organization: cfg.Organization,
},
DNSNames: []string{cfg.CommonName},
NotBefore: notBefore,
NotAfter: now.Add(duration365d * 10).UTC(),
KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature | x509.KeyUsageCertSign,
BasicConstraintsValid: true,
IsCA: true,
}
if len(cfg.CommonName) > 0 {
tmpl.DNSNames = []string{cfg.CommonName}
}
certDERBytes, err := x509.CreateCertificate(cryptorand.Reader, &tmpl, &tmpl, key.Public(), key)
if err != nil {