sigs.k8s.io/cluster-api@v1.7.1/internal/controllers/topology/cluster/structuredmerge/interfaces.go (about)

     1  /*
     2  Copyright 2022 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package structuredmerge
    18  
    19  import (
    20  	"context"
    21  
    22  	"sigs.k8s.io/controller-runtime/pkg/client"
    23  )
    24  
    25  // PatchHelperFactoryFunc defines a func that returns a new PatchHelper.
    26  type PatchHelperFactoryFunc func(ctx context.Context, original, modified client.Object, opts ...HelperOption) (PatchHelper, error)
    27  
    28  // PatchHelper define the behavior for component responsible for managing  patches for Kubernetes objects
    29  // owned by the topology controller.
    30  // NOTE: this interface is required to allow to plug in different PatchHelper implementations, because the
    31  // default one is based on server side apply, and it cannot be used for topology dry run, so we have a
    32  // minimal viable replacement based on two-ways merge.
    33  type PatchHelper interface {
    34  	// HasChanges return true if the modified object is generating changes vs the original object.
    35  	HasChanges() bool
    36  
    37  	// HasSpecChanges return true if the modified object is generating spec changes vs the original object.
    38  	HasSpecChanges() bool
    39  
    40  	// Patch patches the given obj in the Kubernetes cluster.
    41  	Patch(ctx context.Context) error
    42  }