Skip to content

Conversation

pohly
Copy link
Contributor

@pohly pohly commented Jul 17, 2025

What type of PR is this?

/kind feature

What this PR does / why we need it:

When an API uses +listType=map with a certain set of +listMapKeys, it should be possible to extend the API such that new, optional fields can be used as keys. This used to fail with associative list with keys has an element that omits key field "shareUID" (and doesn''t have default value) for a new key shareUID. As of structured-merged-diff v6.3.0 it's supported, see kubernetes-sigs/structured-merge-diff#296 (merged via kubernetes-sigs/structured-merge-diff#298).

Also includes an integration test for SSA with such an optional key.

Which issue(s) this PR is related to:

Fixes #132524

Special notes for your reviewer:

Based on #132998, which in turn was based on my branch.

Diff against #132998 is just some test and commit message cleanup:

diff --git a/test/integration/apimachinery/apply/apply_test.go b/test/integration/apimachinery/apply/apply_test.go
index 204e2234a04..ce51b5299a5 100644
--- a/test/integration/apimachinery/apply/apply_test.go
+++ b/test/integration/apimachinery/apply/apply_test.go
@@ -46,49 +46,40 @@ func init() {
 }
 
 func TestApply(t *testing.T) {
-	// Each sub-test brings up the API server in a certain  configuration.
-	for name, tc := range map[string]struct {
-		extendedTestGroupAPI bool
-		f                    func(tCtx ktesting.TContext)
-	}{
-		"upgrade": {
-			f: func(tCtx ktesting.TContext) {
-				tCtx.Run("", func(tCtx ktesting.TContext) { testApply(tCtx, false) })
-			},
-		},
-	} {
-		t.Run(name, func(t *testing.T) {
-			tCtx := ktesting.Init(t)
-			etcdOptions := framework.SharedEtcd()
-			apiServerOptions := kubeapiservertesting.NewDefaultTestServerOptions()
-			apiServerFlags := framework.DefaultTestServerFlags()
-			runtimeConfigs := []string{"testapigroup.apimachinery.k8s.io/v1=true"}
-			apiServerFlags = append(apiServerFlags, "--runtime-config="+strings.Join(runtimeConfigs, ","))
-
-			if controlplane.AdditionalStorageProvidersForTests != nil {
-				t.Fatal("cannot set AdditionalStorageProvidersForTests, already set")
-			}
-			t.Cleanup(func() {
-				controlplane.AdditionalStorageProvidersForTests = nil
-			})
-			controlplane.AdditionalStorageProvidersForTests = func(client *kubernetes.Clientset) []controlplaneapiserver.RESTStorageProvider {
-				return []controlplaneapiserver.RESTStorageProvider{
-					testapigrouprest.RESTStorageProvider{NamespaceClient: client.CoreV1().Namespaces()},
-				}
-			}
-
-			server := kubeapiservertesting.StartTestServerOrDie(t, apiServerOptions, apiServerFlags, etcdOptions)
-			tCtx.CleanupCtx(func(tCtx ktesting.TContext) {
-				tCtx.Log("Stopping the apiserver...")
-				server.TearDownFn()
-			})
-			tCtx = ktesting.WithRESTConfig(tCtx, server.ClientConfig)
-			tc.f(tCtx)
-		})
+	tCtx := ktesting.Init(t)
+	etcdOptions := framework.SharedEtcd()
+	apiServerOptions := kubeapiservertesting.NewDefaultTestServerOptions()
+	apiServerFlags := framework.DefaultTestServerFlags()
+	runtimeConfigs := []string{"testapigroup.apimachinery.k8s.io/v1=true"}
+	apiServerFlags = append(apiServerFlags, "--runtime-config="+strings.Join(runtimeConfigs, ","))
+
+	// Sanity check. Not protected against concurrent access, but that's
+	// okay: integration tests are also run with race detection, so that
+	// would catch it.
+	if controlplane.AdditionalStorageProvidersForTests != nil {
+		t.Fatal("cannot set AdditionalStorageProvidersForTests, already set")
+	}
+	t.Cleanup(func() {
+		controlplane.AdditionalStorageProvidersForTests = nil
+	})
+	controlplane.AdditionalStorageProvidersForTests = func(client *kubernetes.Clientset) []controlplaneapiserver.RESTStorageProvider {
+		return []controlplaneapiserver.RESTStorageProvider{
+			testapigrouprest.RESTStorageProvider{NamespaceClient: client.CoreV1().Namespaces()},
+		}
 	}
+
+	server := kubeapiservertesting.StartTestServerOrDie(t, apiServerOptions, apiServerFlags, etcdOptions)
+	tCtx.CleanupCtx(func(tCtx ktesting.TContext) {
+		tCtx.Log("Stopping the apiserver...")
+		server.TearDownFn()
+	})
+	tCtx = ktesting.WithRESTConfig(tCtx, server.ClientConfig)
+
+	// More sub-tests could be added here. Currently there's only one.
+	tCtx.Run("optional-list-map-key", testOptionalListMapKey)
 }
 
-func testApply(tCtx ktesting.TContext, upgrade bool) {
+func testOptionalListMapKey(tCtx ktesting.TContext) {
 	requireManagedFields := func(what string, obj *unstructured.Unstructured, expectedManagedFields any) {
 		tCtx.Helper()
 		actualManagedFields, _, _ := unstructured.NestedFieldCopy(obj.Object, "metadata", "managedFields")

Does this PR introduce a user-facing change?

NONE

/assign @jpbetz @liggitt

pohly and others added 3 commits July 17, 2025 09:56
test/integration/apiserver/apply covers the behavior of server-side-apply (SSA)
for official APIs. But there seem to be no integration tests which cover the
semantic of SSA like adding/removing/updating entries in a list map. This adds
such a test.

It needs an API which is under control of the test and uses
k8s.io/apimachinery/pkg/apis/testapigroup for that purpose, with some issues
fixed (OpenAPI code generation complained) and a new list map added.

Registering that API group in the apiserver needs a REST storage and
strategy. The API group only gets added in the test. However, the production
code has to know about it. In particular,
pkg/generated/openapi/zz_generated.openapi.go has to describe it.
As of structured-merge-diff v6.3.0, list map keys may be optional, as long as
at least one key is provided.
@k8s-ci-robot k8s-ci-robot added the release-note-none Denotes a PR that doesn't merit a release note. label Jul 17, 2025
@k8s-ci-robot k8s-ci-robot added kind/feature Categorizes issue or PR as related to a new feature. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Jul 17, 2025
@k8s-ci-robot
Copy link
Contributor

This issue is currently awaiting triage.

If a SIG or subproject determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. area/apiserver area/cloudprovider area/code-generation area/dependency Issues or PRs related to dependency changes area/kube-proxy area/kubectl area/kubelet area/test kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/architecture Categorizes an issue or PR as relevant to SIG Architecture. sig/auth Categorizes an issue or PR as relevant to SIG Auth. sig/cli Categorizes an issue or PR as relevant to SIG CLI. sig/cloud-provider Categorizes an issue or PR as relevant to SIG Cloud Provider. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Jul 17, 2025
@k8s-ci-robot k8s-ci-robot added the sig/node Categorizes an issue or PR as relevant to SIG Node. label Jul 17, 2025
@k8s-ci-robot k8s-ci-robot added the sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. label Jul 17, 2025
@k8s-ci-robot k8s-ci-robot requested review from a team and aojea July 17, 2025 08:05
@k8s-ci-robot k8s-ci-robot added the sig/storage Categorizes an issue or PR as relevant to SIG Storage. label Jul 17, 2025
@k8s-ci-robot k8s-ci-robot added the sig/testing Categorizes an issue or PR as relevant to SIG Testing. label Jul 17, 2025
@k8s-ci-robot k8s-ci-robot added the wg/device-management Categorizes an issue or PR as relevant to WG Device Management. label Jul 17, 2025
@k8s-triage-robot
Copy link

This PR may require API review.

If so, when the changes are ready, complete the pre-review checklist and request an API review.

Status of requested reviews is tracked in the API Review project.

@liggitt
Copy link
Member

liggitt commented Jul 17, 2025

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 17, 2025
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 0a7b0eaf56c33f5bfd88b904fc0fbde6b0fa1ff9

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: liggitt, pohly

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 17, 2025
@k8s-ci-robot k8s-ci-robot merged commit d33af7f into kubernetes:master Jul 17, 2025
14 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.34 milestone Jul 17, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in SIG Node CI/Test Board Jul 17, 2025
@github-project-automation github-project-automation bot moved this to Closed / Done in SIG Auth Jul 17, 2025
@github-project-automation github-project-automation bot moved this from Needs Triage to Done in SIG CLI Jul 17, 2025
@pohly pohly moved this from 🆕 New to ✅ Done in Dynamic Resource Allocation Jul 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. area/apiserver area/cloudprovider area/code-generation area/dependency Issues or PRs related to dependency changes area/kube-proxy area/kubectl area/kubelet area/test cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. release-note-none Denotes a PR that doesn't merit a release note. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/architecture Categorizes an issue or PR as relevant to SIG Architecture. sig/auth Categorizes an issue or PR as relevant to SIG Auth. sig/cli Categorizes an issue or PR as relevant to SIG CLI. sig/cloud-provider Categorizes an issue or PR as relevant to SIG Cloud Provider. sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. sig/instrumentation Categorizes an issue or PR as relevant to SIG Instrumentation. sig/network Categorizes an issue or PR as relevant to SIG Network. sig/node Categorizes an issue or PR as relevant to SIG Node. sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. sig/storage Categorizes an issue or PR as relevant to SIG Storage. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. wg/device-management Categorizes an issue or PR as relevant to WG Device Management.

Projects

Status: Done
Archived in project
Archived in project

Development

Successfully merging this pull request may close these issues.

API: support adding new keys to listType=map

5 participants