Skip to content

Commit

Permalink
add take over and drift detection options
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Zhang committed Aug 14, 2024
1 parent b7e094d commit e029576
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 16 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:

- name: Set up Ginkgo CLI
run: |
go install github.com/onsi/ginkgo/v2/ginkgo@v2.9.5
go install github.com/onsi/ginkgo/v2/ginkgo@v2.19.1
- name: Run unit tests & Generate coverage
run: make test
Expand Down Expand Up @@ -86,7 +86,7 @@ jobs:
HUB_SERVER_URL: 'https://172.19.0.2:6443'

e2e-tests:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
needs: [
detect-noop,
]
Expand All @@ -102,13 +102,13 @@ jobs:

- name: Install Ginkgo CLI
run: |
go install github.com/onsi/ginkgo/v2/ginkgo@v2.13.0
go install github.com/onsi/ginkgo/v2/ginkgo@v2.19.1
- name: Install Kind
# Before updating the kind version to use, verify that the current kind image
# is still supported by the version.
run: |
go install sigs.k8s.io/kind@v0.20.0
go install sigs.k8s.io/kind@v0.22.0
- name: Run e2e tests
run: |
Expand Down
73 changes: 71 additions & 2 deletions apis/placement/v1beta1/clusterresourceplacement_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,12 +420,81 @@ type RolloutStrategy struct {
// +optional
RollingUpdate *RollingUpdateConfig `json:"rollingUpdate,omitempty"`

// ApplyStrategy describes how to resolve the conflict if the resource to be placed already exists in the target cluster
// and is owned by other appliers.
// ConflictResolutionStrategy describes how to resolve conflicts if the resource to be placed already exists in the target cluster.
// +optional
ConflictResolutionStrategy *ConflictResolutionStrategy `json:"conflictResolutionStrategy,omitempty"`

// ApplyStrategy describes how to apply the resource to the target cluster.
// +optional
ApplyStrategy *ApplyStrategy `json:"applyStrategy,omitempty"`
}

// ConflictResolutionStrategy describes the strategy used to resolve the conflict if the resource
// to be placed already exists in the target cluster.
type ConflictResolutionStrategy struct {
// type describes the type of the strategy used to resolve the conflict
// +kubebuilder:default=AlwaysApply
// +kubebuilder:validation:Enum=AlwaysApply;Report;ApplyIfNoDiff;Recreate
// +optional
Type ConflictResolutionType `json:"type,omitempty"`

// DiffCalculateStrategy describes how to calculate the diff between the resource on
// the hub cluster and the existing resources on the member cluster.
// +optional
DiffCalculateStrategy DiffCalculateStrategy `json:"whenToDeclearDiff,omitempty"`
}

// ConflictResolutionType describes the type of the strategy used to resolve the conflict
// if the resource to be placed already exists in the target cluster.
// +enum
type ConflictResolutionType string

const (
// ConflictResolutionTypeReport will report the conflict and fail the apply.
ConflictResolutionTypeReport ConflictResolutionType = "Report"

// ConflictResolutionTypeApplyIfNoDiff will apply the yaml from hub cluster using the
// applyStrategy if there is no difference between the resource on the hub cluster and
// the existing resources on the member cluster.
ConflictResolutionTypeApplyIfNoDiff ConflictResolutionType = "ApplyIfNoDiff"

// ConflictResolutionTypeAlwaysApply will always apply the resource to the member cluster.
ConflictResolutionTypeAlwaysApply ConflictResolutionType = "AlwaysApply"

// ConflictResolutionTypeRecreate will delete and recreate the resource based on the hub cluster
// resource manifest to the member cluster.
ConflictResolutionTypeRecreate ConflictResolutionType = "Recreate"
)

// DiffCalculateStrategy describes how to calculate the diff between the resource on the
// hub cluster and the existing resources on the member cluster.
type DiffCalculateStrategy struct {
// type describes the type of the strategy used to calculate the diff.
// +kubebuilder:default=Never
// +kubebuilder:validation:Enum=Never;ExistingFieldDiffOnly;Recreate
// +optional
Type DiffCalculateStrategyType `json:"type,omitempty"`
}

// DiffCalculateStrategyType describes the type of the strategy used to calculate the diff.
// +enum
type DiffCalculateStrategyType string

const (
// DiffCalculateStrategyTypeNever will never calculate the diff between the resource on the hub cluster
// and the existing resources on the member cluster.
DiffCalculateStrategyTypeNever DiffCalculateStrategyType = "Never"

// DiffCalculateStrategyTypeHubFieldsOnly will calculate the diff between the resource on the hub cluster
// and the existing resources on the member cluster but the diff will be calculated only on
// the fields that are present in the hub cluster resource manifest.
DiffCalculateStrategyTypeHubFieldsOnly DiffCalculateStrategyType = "HubFieldsOnly"

// DiffCalculateStrategyTypeAllFields will calculate the diff between the resource on the hub cluster
// and the existing resources on the member cluster on all fields.
DiffCalculateStrategyTypeAllFields DiffCalculateStrategyType = "AllFields"
)

// ApplyStrategy describes how to resolve the conflict if the resource to be placed already exists in the target cluster
// and whether it's allowed to be co-owned by other non-fleet appliers.
// Note: If multiple CRPs try to place the same resource with different apply strategy, the later ones will fail with the
Expand Down
38 changes: 37 additions & 1 deletion apis/placement/v1beta1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -1753,9 +1753,8 @@ spec:
with new ones.
properties:
applyStrategy:
description: |-
ApplyStrategy describes how to resolve the conflict if the resource to be placed already exists in the target cluster
and is owned by other appliers.
description: ApplyStrategy describes how to apply the resource
to the target cluster.
properties:
allowCoOwnership:
description: |-
Expand Down Expand Up @@ -1791,6 +1790,37 @@ spec:
- ServerSideApply
type: string
type: object
conflictResolutionStrategy:
description: ConflictResolutionStrategy describes how to resolve
conflicts if the resource to be placed already exists in the
target cluster.
properties:
type:
default: AlwaysApply
description: type describes the type of the strategy used
to resolve the conflict
enum:
- AlwaysApply
- Report
- ApplyIfNoDiff
- Recreate
type: string
whenToDeclearDiff:
description: |-
DiffCalculateStrategy describes how to calculate the diff between the resource on
the hub cluster and the existing resources on the member cluster.
properties:
type:
default: Never
description: type describes the type of the strategy used
to calculate the diff.
enum:
- Never
- ExistingFieldDiffOnly
- Recreate
type: string
type: object
type: object
rollingUpdate:
description: Rolling update config params. Present only if RolloutStrategyType
= RollingUpdate.
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ require (
github.com/evanphx/json-patch/v5 v5.9.0
github.com/go-logr/logr v1.4.2
github.com/google/go-cmp v0.6.0
github.com/onsi/ginkgo/v2 v2.17.2
github.com/onsi/gomega v1.33.1
github.com/onsi/ginkgo/v2 v2.19.1
github.com/onsi/gomega v1.34.0
github.com/prometheus/client_golang v1.19.1
github.com/prometheus/client_model v0.6.1
github.com/spf13/cobra v1.8.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/onsi/ginkgo/v2 v2.17.2 h1:7eMhcy3GimbsA3hEnVKdw/PQM9XN9krpKVXsZdph0/g=
github.com/onsi/ginkgo/v2 v2.17.2/go.mod h1:nP2DPOQoNsQmsVyv5rDA8JkXQoCs6goXIvr/PRJ1eCc=
github.com/onsi/gomega v1.33.1 h1:dsYjIxxSR755MDmKVsaFQTE22ChNBcuuTWgkUDSubOk=
github.com/onsi/gomega v1.33.1/go.mod h1:U4R44UsT+9eLIaYRB2a5qajjtQYn0hauxvRm16AVYg0=
github.com/onsi/ginkgo/v2 v2.19.1 h1:QXgq3Z8Crl5EL1WBAC98A5sEBHARrAJNzAmMxzLcRF0=
github.com/onsi/ginkgo/v2 v2.19.1/go.mod h1:O3DtEWQkPa/F7fBMgmZQKKsluAy8pd3rEQdrjkPb9zA=
github.com/onsi/gomega v1.34.0 h1:eSSPsPNp6ZpsG8X1OVmOTxig+CblTc4AxpPBykhe2Os=
github.com/onsi/gomega v1.34.0/go.mod h1:MIKI8c+f+QLWk+hxbePD4i0LMJSExPaZOVfkoex4cAo=
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ=
Expand Down

0 comments on commit e029576

Please sign in to comment.