...

Source file src/sigs.k8s.io/cli-utils/test/e2e/serverside_apply_test.go

Documentation: sigs.k8s.io/cli-utils/test/e2e

     1  // Copyright 2020 The Kubernetes Authors.
     2  // SPDX-License-Identifier: Apache-2.0
     3  
     4  package e2e
     5  
     6  import (
     7  	"context"
     8  	"time"
     9  
    10  	. "github.com/onsi/ginkgo/v2"
    11  	. "github.com/onsi/gomega"
    12  	v1 "k8s.io/api/core/v1"
    13  	"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
    14  	"sigs.k8s.io/cli-utils/pkg/apply"
    15  	"sigs.k8s.io/cli-utils/pkg/common"
    16  	"sigs.k8s.io/cli-utils/pkg/object"
    17  	"sigs.k8s.io/cli-utils/test/e2e/e2eutil"
    18  	"sigs.k8s.io/cli-utils/test/e2e/invconfig"
    19  	"sigs.k8s.io/controller-runtime/pkg/client"
    20  )
    21  
    22  func serversideApplyTest(ctx context.Context, c client.Client, invConfig invconfig.InventoryConfig, inventoryName, namespaceName string) {
    23  	By("Apply a Deployment and an APIService by server-side apply")
    24  	applier := invConfig.ApplierFactoryFunc()
    25  
    26  	inv := invConfig.InvWrapperFunc(invConfig.FactoryFunc(inventoryName, namespaceName, "test"))
    27  	firstResources := []*unstructured.Unstructured{
    28  		e2eutil.WithNamespace(e2eutil.ManifestToUnstructured(deployment1), namespaceName),
    29  		e2eutil.ManifestToUnstructured(apiservice1),
    30  	}
    31  
    32  	e2eutil.RunWithNoErr(applier.Run(ctx, inv, firstResources, apply.ApplierOptions{
    33  		ReconcileTimeout: 2 * time.Minute,
    34  		EmitStatusEvents: true,
    35  		ServerSideOptions: common.ServerSideOptions{
    36  			ServerSideApply: true,
    37  			ForceConflicts:  true,
    38  			FieldManager:    "test",
    39  		},
    40  	}))
    41  
    42  	By("Verify deployment is server-side applied")
    43  	result := e2eutil.AssertUnstructuredExists(ctx, c, e2eutil.WithNamespace(e2eutil.ManifestToUnstructured(deployment1), namespaceName))
    44  
    45  	// LastAppliedConfigAnnotation annotation is only set for client-side apply and we've server-side applied here.
    46  	_, found, err := object.NestedField(result.Object, "metadata", "annotations", v1.LastAppliedConfigAnnotation)
    47  	Expect(err).NotTo(HaveOccurred())
    48  	Expect(found).To(BeFalse())
    49  
    50  	manager, found, err := object.NestedField(result.Object, "metadata", "managedFields", 0, "manager")
    51  	Expect(err).NotTo(HaveOccurred())
    52  	Expect(found).To(BeTrue())
    53  	Expect(manager).To(Equal("test"))
    54  
    55  	By("Verify APIService is server-side applied")
    56  	result = e2eutil.AssertUnstructuredExists(ctx, c, e2eutil.ManifestToUnstructured(apiservice1))
    57  
    58  	// LastAppliedConfigAnnotation annotation is only set for client-side apply and we've server-side applied here.
    59  	_, found, err = object.NestedField(result.Object, "metadata", "annotations", v1.LastAppliedConfigAnnotation)
    60  	Expect(err).NotTo(HaveOccurred())
    61  	Expect(found).To(BeFalse())
    62  
    63  	manager, found, err = object.NestedField(result.Object, "metadata", "managedFields", 0, "manager")
    64  	Expect(err).NotTo(HaveOccurred())
    65  	Expect(found).To(BeTrue())
    66  	Expect(manager).To(Equal("test"))
    67  }
    68  

View as plain text