github.com/verrazzano/verrazzano@v1.7.1/pkg/kubectlutil/kubectl_util.go (about)

     1  // Copyright (c) 2023, Oracle and/or its affiliates.
     2  // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
     3  
     4  package kubectlutil
     5  
     6  import (
     7  	"fmt"
     8  
     9  	"k8s.io/api/core/v1"
    10  	"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
    11  	"k8s.io/apimachinery/pkg/runtime"
    12  	"k8s.io/kubectl/pkg/util"
    13  )
    14  
    15  // SetLastAppliedConfigurationAnnotation applies the kubectl.kubernetes.io/last-applied-configuration annotation
    16  // in order to calculate correct 3-way merges between object configuration file/configuration file,
    17  // live object configuration/live configuration and declarative configuration writer/declarative writer
    18  // (e.g. vz cli install or upgrade)
    19  func SetLastAppliedConfigurationAnnotation(obj runtime.Object) error {
    20  	err := util.CreateOrUpdateAnnotation(true, obj, unstructured.UnstructuredJSONScheme)
    21  	if err != nil {
    22  		return fmt.Errorf("error while applying %s annotation on the "+
    23  			"object: %v", v1.LastAppliedConfigAnnotation, err)
    24  	}
    25  	return nil
    26  }