mirror of
https://github.com/1Password/onepassword-operator.git
synced 2025-10-24 08:20:45 +00:00
Upgrade Operator SDK to v1.34.1 and update dependencies (#185)
This does the following updates: * Upgrade to Operator SDK v1.34.1. This fixes building multi-arch images from Makefile. Check this MR from operator-framework for details. * Update Go dependencies. This addresses Dependabot alert ["Golang protojson.Unmarshal function infinite loop when unmarshaling certain forms of invalid JSON"](https://github.com/1Password/onepassword-operator/security/dependabot/13). * Update versions of the GitHub Actions used in the pipelines. * Update Kubernetes related tools (such as controller-tools version, and operator-sdk for ci pipelines) By updating dependencies, the pipelines no longer fail due to a panic error when running `make test`.
This commit is contained in:
94
vendor/sigs.k8s.io/controller-runtime/pkg/controller/controllerutil/controllerutil.go
generated
vendored
94
vendor/sigs.k8s.io/controller-runtime/pkg/controller/controllerutil/controllerutil.go
generated
vendored
@@ -27,7 +27,7 @@ import (
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/utils/pointer"
|
||||
"k8s.io/utils/ptr"
|
||||
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
|
||||
@@ -77,8 +77,8 @@ func SetControllerReference(owner, controlled metav1.Object, scheme *runtime.Sch
|
||||
Kind: gvk.Kind,
|
||||
Name: owner.GetName(),
|
||||
UID: owner.GetUID(),
|
||||
BlockOwnerDeletion: pointer.Bool(true),
|
||||
Controller: pointer.Bool(true),
|
||||
BlockOwnerDeletion: ptr.To(true),
|
||||
Controller: ptr.To(true),
|
||||
}
|
||||
|
||||
// Return early with an error if the object is already controlled.
|
||||
@@ -121,6 +121,84 @@ func SetOwnerReference(owner, object metav1.Object, scheme *runtime.Scheme) erro
|
||||
return nil
|
||||
}
|
||||
|
||||
// RemoveOwnerReference is a helper method to make sure the given object removes an owner reference to the object provided.
|
||||
// This allows you to remove the owner to establish a new owner of the object in a subsequent call.
|
||||
func RemoveOwnerReference(owner, object metav1.Object, scheme *runtime.Scheme) error {
|
||||
owners := object.GetOwnerReferences()
|
||||
length := len(owners)
|
||||
if length < 1 {
|
||||
return fmt.Errorf("%T does not have any owner references", object)
|
||||
}
|
||||
ro, ok := owner.(runtime.Object)
|
||||
if !ok {
|
||||
return fmt.Errorf("%T is not a runtime.Object, cannot call RemoveOwnerReference", owner)
|
||||
}
|
||||
gvk, err := apiutil.GVKForObject(ro, scheme)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
index := indexOwnerRef(owners, metav1.OwnerReference{
|
||||
APIVersion: gvk.GroupVersion().String(),
|
||||
Name: owner.GetName(),
|
||||
Kind: gvk.Kind,
|
||||
})
|
||||
if index == -1 {
|
||||
return fmt.Errorf("%T does not have an owner reference for %T", object, owner)
|
||||
}
|
||||
|
||||
owners = append(owners[:index], owners[index+1:]...)
|
||||
object.SetOwnerReferences(owners)
|
||||
return nil
|
||||
}
|
||||
|
||||
// HasControllerReference returns true if the object
|
||||
// has an owner ref with controller equal to true
|
||||
func HasControllerReference(object metav1.Object) bool {
|
||||
owners := object.GetOwnerReferences()
|
||||
for _, owner := range owners {
|
||||
isTrue := owner.Controller
|
||||
if owner.Controller != nil && *isTrue {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// RemoveControllerReference removes an owner reference where the controller
|
||||
// equals true
|
||||
func RemoveControllerReference(owner, object metav1.Object, scheme *runtime.Scheme) error {
|
||||
if ok := HasControllerReference(object); !ok {
|
||||
return fmt.Errorf("%T does not have a owner reference with controller equals true", object)
|
||||
}
|
||||
ro, ok := owner.(runtime.Object)
|
||||
if !ok {
|
||||
return fmt.Errorf("%T is not a runtime.Object, cannot call RemoveControllerReference", owner)
|
||||
}
|
||||
gvk, err := apiutil.GVKForObject(ro, scheme)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ownerRefs := object.GetOwnerReferences()
|
||||
index := indexOwnerRef(ownerRefs, metav1.OwnerReference{
|
||||
APIVersion: gvk.GroupVersion().String(),
|
||||
Name: owner.GetName(),
|
||||
Kind: gvk.Kind,
|
||||
})
|
||||
|
||||
if index == -1 {
|
||||
return fmt.Errorf("%T does not have an controller reference for %T", object, owner)
|
||||
}
|
||||
|
||||
if ownerRefs[index].Controller == nil || !*ownerRefs[index].Controller {
|
||||
return fmt.Errorf("%T owner is not the controller reference for %T", owner, object)
|
||||
}
|
||||
|
||||
ownerRefs = append(ownerRefs[:index], ownerRefs[index+1:]...)
|
||||
object.SetOwnerReferences(ownerRefs)
|
||||
return nil
|
||||
}
|
||||
|
||||
func upsertOwnerRef(ref metav1.OwnerReference, object metav1.Object) {
|
||||
owners := object.GetOwnerReferences()
|
||||
if idx := indexOwnerRef(owners, ref); idx == -1 {
|
||||
@@ -166,7 +244,6 @@ func referSameObject(a, b metav1.OwnerReference) bool {
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return aGV.Group == bGV.Group && a.Kind == b.Kind && a.Name == b.Name
|
||||
}
|
||||
|
||||
@@ -193,6 +270,9 @@ const ( // They should complete the sentence "Deployment default/foo has been ..
|
||||
// The MutateFn is called regardless of creating or updating an object.
|
||||
//
|
||||
// It returns the executed operation and an error.
|
||||
//
|
||||
// Note: changes made by MutateFn to any sub-resource (status...), will be
|
||||
// discarded.
|
||||
func CreateOrUpdate(ctx context.Context, c client.Client, obj client.Object, f MutateFn) (OperationResult, error) {
|
||||
key := client.ObjectKeyFromObject(obj)
|
||||
if err := c.Get(ctx, key, obj); err != nil {
|
||||
@@ -230,6 +310,12 @@ func CreateOrUpdate(ctx context.Context, c client.Client, obj client.Object, f M
|
||||
// The MutateFn is called regardless of creating or updating an object.
|
||||
//
|
||||
// It returns the executed operation and an error.
|
||||
//
|
||||
// Note: changes to any sub-resource other than status will be ignored.
|
||||
// Changes to the status sub-resource will only be applied if the object
|
||||
// already exist. To change the status on object creation, the easiest
|
||||
// way is to requeue the object in the controller if OperationResult is
|
||||
// OperationResultCreated
|
||||
func CreateOrPatch(ctx context.Context, c client.Client, obj client.Object, f MutateFn) (OperationResult, error) {
|
||||
key := client.ObjectKeyFromObject(obj)
|
||||
if err := c.Get(ctx, key, obj); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user