Skip to content

Commit

Permalink
add delete type override
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Zhang committed Nov 24, 2024
1 parent b7fd384 commit 01acd89
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
22 changes: 20 additions & 2 deletions apis/placement/v1alpha1/override_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type OverridePolicy struct {
// OverrideRules defines an array of override rules to be applied on the selected resources.
// The order of the rules determines the override order.
// When there are two rules selecting the same fields on the target cluster, the last one will win.
// There can only be one override rule if it is a `Delete` type override rule.
// You can have 1-20 rules.
// +kubebuilder:validation:Required
// +kubebuilder:validation:MinItems=1
Expand All @@ -66,6 +67,12 @@ type OverridePolicy struct {

// OverrideRule defines how to override the selected resources on the target clusters.
type OverrideRule struct {
// OverrideType defines the type of the override rules.
// +kubebuilder:validation:Enum=JSONPatch;Delete
// +kubebuilder:default:JSONPatch
// +optional
OverrideType OverrideType `json:"overrideType,omitempty"`

// ClusterSelectors selects the target clusters.
// The resources will be overridden before applying to the matching clusters.
// An empty clusterSelector selects ALL the member clusters.
Expand All @@ -78,10 +85,21 @@ type OverrideRule struct {
// +kubebuilder:validation:Required
// +kubebuilder:validation:MinItems=1
// +kubebuilder:validation:MaxItems=20
// +required
JSONPatchOverrides []JSONPatchOverride `json:"jsonPatchOverrides"`
// +optional
JSONPatchOverrides []JSONPatchOverride `json:"jsonPatchOverrides,omitempty"`
}

// OverrideType defines the type of Override
type OverrideType string

const (
// JSONPatchOverrideType applies a JSON patch on the selected resources following [RFC 6902](https://datatracker.ietf.org/doc/html/rfc6902).
JSONPatchOverrideType OverrideType = "JSONPatch"

// DeleteOverrideType deletes the selected resources on the target clusters.
DeleteOverrideType OverrideType = "Delete"
)

// +genclient
// +genclient:Namespaced
// +kubebuilder:object:root=true
Expand Down
5 changes: 3 additions & 2 deletions apis/placement/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pkg/controllers/updaterun/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"fmt"
"time"

"go.goms.io/fleet/pkg/utils"
"go.goms.io/fleet/pkg/utils/controller"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/tools/record"
"k8s.io/client-go/util/workqueue"
Expand All @@ -27,6 +25,8 @@ import (
"sigs.k8s.io/controller-runtime/pkg/reconcile"

placementv1alpha1 "go.goms.io/fleet/apis/placement/v1alpha1"
"go.goms.io/fleet/pkg/utils"
"go.goms.io/fleet/pkg/utils/controller"
)

// Reconciler reconciles a ClusterStagedUpdateRun object.
Expand Down
3 changes: 2 additions & 1 deletion pkg/controllers/updaterun/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ package updaterun
import (
"testing"

placementv1alpha1 "go.goms.io/fleet/apis/placement/v1alpha1"
"k8s.io/client-go/util/workqueue"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllertest"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

placementv1alpha1 "go.goms.io/fleet/apis/placement/v1alpha1"
)

func TestHandleClusterApprovalRequest(t *testing.T) {
Expand Down

0 comments on commit 01acd89

Please sign in to comment.