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

OCPBUGS-50587: apiserver/patch: update patch tests to use server side apply #29558

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions test/extended/apiserver/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,13 @@ var _ = g.Describe("[sig-api-machinery] JSON Patch [apigroup:operator.openshift.
func createWellKnownKubeAPIServerOperatorResource(ctx context.Context, resourceClient dynamic.ResourceInterface) *operatorv1.KubeAPIServer {
kasOperatorYaml := testdata.MustAsset("test/extended/testdata/apiserver/operator-kube-apiserver-cr.yaml")
unstructuredKasOperatorManifest := resourceread.ReadUnstructuredOrDie(kasOperatorYaml)
unstructuredKasOperator, err := resourceClient.Create(ctx, unstructuredKasOperatorManifest, metav1.CreateOptions{})
unstructuredKasOperator, err := resourceClient.Create(ctx, unstructuredKasOperatorManifest, metav1.CreateOptions{FieldManager: "origin-patchgo"})
o.Expect(err).NotTo(o.HaveOccurred())

kasOperator := unstructuredToKubeAPIServerOperator(unstructuredKasOperator.Object)
kasOperatorFromManifest := unstructuredToKubeAPIServerOperator(unstructuredKasOperatorManifest.Object)
kasOperator.Status = kasOperatorFromManifest.Status
unstructuredKasOperator, err = resourceClient.UpdateStatus(ctx, kubeAPIServerOperatorToUnstructured(kasOperator), metav1.UpdateOptions{})
unstructuredKasOperator, err = resourceClient.ApplyStatus(ctx, kasOperator.Name, kubeAPIServerOperatorToUnstructured(kasOperator), metav1.ApplyOptions{FieldManager: "origin-patchgo"})
o.Expect(err).NotTo(o.HaveOccurred())
kasOperator = unstructuredToKubeAPIServerOperator(unstructuredKasOperator.Object)
o.Expect(kasOperator.Status.NodeStatuses).To(o.Equal([]operatorv1.NodeStatus{
Expand Down Expand Up @@ -203,6 +203,23 @@ func unstructuredToKubeAPIServerOperator(obj map[string]interface{}) *operatorv1
func kubeAPIServerOperatorToUnstructured(kasOperator *operatorv1.KubeAPIServer) *unstructured.Unstructured {
raw, err := runtime.DefaultUnstructuredConverter.ToUnstructured(kasOperator)
o.Expect(err).NotTo(o.HaveOccurred())

// We are not going to allow setting NodeStatus.CurrentRevision on creation of a NodeStatus.
// Ensure we remove the current revision from the node status every time because
// NodeStatus.CurrentRevision doesn't have omitempty in the JSON tag on the API.
nodeStatuses, ok, err := unstructured.NestedSlice(raw, "status", "nodeStatuses")
o.Expect(err).NotTo(o.HaveOccurred())
if ok {
newNodeStatuses := []interface{}{}
for _, nodeStatus := range nodeStatuses {
unstructured.RemoveNestedField(nodeStatus.(map[string]interface{}), "currentRevision")
newNodeStatuses = append(newNodeStatuses, nodeStatus)
}

err = unstructured.SetNestedField(raw, newNodeStatuses, "status", "nodeStatuses")
o.Expect(err).NotTo(o.HaveOccurred())
}

return &unstructured.Unstructured{Object: raw}
}

Expand Down