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

Make ApplyConfigurations dynamically extractable in tests #1322

Closed
therealmitchconnors opened this issue Dec 9, 2023 · 5 comments
Closed
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.

Comments

@therealmitchconnors
Copy link

SSA and ApplyConfigurations are great, but writing dynamic (that is, not specific to any one kubernetes type) logic seems to be currently untestable due to how applyconfigurations are organized. I'm trying to write logic for any kubernetes type that can 1) accept and apply an arbitrary applyconfig to a dynamic resource client, and 2) when the underlying collection changes, extract an applyconfig from the latest object, and compare it to the most recently applied applyconfig, triggering a re-apply if the two differ. This seems to be the primary use case for apply, except that it is done using a dynamic client rather than typed clients.

The following code appears to work when running against a live api server (pseudo code for brevity):

func repro(d discovery.DiscoveryInterface, c dynamic.Interface) {
	cm := &unstructured.Unstructured{
		Object: map[string]interface{}{
			"data": map[string]interface{}{
				"key": "value",
			},
		},
	}
	ex, _ := metaac.NewUnstructuredExtractor(d)
	inf := dynamicinformer.NewDynamicSharedInformerFactory(c, time.Minute).
		ForResource(gvr.ConfigMap)
	inf.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
		UpdateFunc: func(oldObj, newObj interface{}) {
			uObj := newObj.(unstructured.Unstructured)
			cmac, _ := ex.Extract(&uObj, "repro")
		},
	})
	cmr := c.Resource(gvr.ConfigMap)
	cmr.Namespace("default").
		Apply(context.Background(), "name", cm, metav1.ApplyOptions{
			FieldManager: "repro",
		})
}

However, when the above code is passed a *fakediscovery.FakeDiscovery as d, the code results in a panic. This is because the FakeDiscovery server returns an empty Open API document at OpenAPISchema(), which the UnstructuredExtractor depends on being non-empty.

Typed clients bypass this problem by accessing embedded open api schema in their respective internal packages such as https://github.com/kubernetes/client-go/blob/master/applyconfigurations/internal/internal.go#L41, but this schema is not directly available to the FakeClient in a unit test.

In order for dynamic SSA to be testable, the internal packages of typed clients should be moved to an importable location.

@howardjohn
Copy link
Contributor

cc @apelisse

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle stale
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Mar 10, 2024
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle rotten
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Apr 9, 2024
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

@k8s-ci-robot
Copy link
Contributor

@k8s-triage-robot: Closing this issue, marking it as "Not Planned".

In response to this:

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

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 closed this as not planned Won't fix, can't repro, duplicate, stale May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.
Projects
None yet
Development

No branches or pull requests

4 participants