Skip to content

feat: drift detection and takeover implementation (1/) #985

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apis/placement/v1beta1/work_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ const (

// WorkConditionTypeAvailable represents workload in Work is available on the spoke cluster.
WorkConditionTypeAvailable = "Available"

// WorkConditionTypeDiffReported reports whether Fleet has successfully reported the
// configuration difference between the states in the hub cluster and a member cluster.
WorkConditionTypeDiffReported = "DiffReported"
)

// This api is copied from https://github.com/kubernetes-sigs/work-api/blob/master/pkg/apis/v1alpha1/work_types.go.
Expand Down
8 changes: 7 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ require (
github.com/onsi/gomega v1.35.1
github.com/prometheus/client_golang v1.19.1
github.com/prometheus/client_model v0.6.1
github.com/qri-io/jsonpointer v0.1.1
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.9.0
go.goms.io/fleet-networking v0.2.7
github.com/wI2L/jsondiff v0.6.0
go.goms.io/fleet-networking v0.2.11
go.uber.org/atomic v1.11.0
go.uber.org/zap v1.27.0
golang.org/x/exp v0.0.0-20241004190924-225e2abe05e6
Expand Down Expand Up @@ -102,6 +104,10 @@ require (
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/samber/lo v1.38.1 // indirect
github.com/tidwall/gjson v1.18.0 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
github.com/tidwall/sjson v1.2.5 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.52.0 // indirect
go.opentelemetry.io/otel v1.31.0 // indirect
go.opentelemetry.io/otel/metric v1.31.0 // indirect
Expand Down
18 changes: 16 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ github.com/prometheus/common v0.55.0 h1:KEi6DK7lXW/m7Ig5i47x0vRzuBsHuvJdi5ee6Y3G
github.com/prometheus/common v0.55.0/go.mod h1:2SECS4xJG1kd8XF9IcM1gMX6510RAEL65zxzNImwdc8=
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
github.com/qri-io/jsonpointer v0.1.1 h1:prVZBZLL6TW5vsSB9fFHFAMBLI4b0ri5vribQlTJiBA=
github.com/qri-io/jsonpointer v0.1.1/go.mod h1:DnJPaYgiKu56EuDp8TU5wFLdZIcAnb/uH9v37ZaMV64=
github.com/redis/go-redis/v9 v9.6.1 h1:HHDteefn6ZkTtY5fGUE8tj8uy85AHk6zP7CpzIAM0y4=
github.com/redis/go-redis/v9 v9.6.1/go.mod h1:0C0c6ycQsdpVNQpxb1njEQIqkx5UcsM8FJCQLgE9+RA=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
Expand All @@ -232,11 +234,23 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/gjson v1.18.0 h1:FIDeeyB800efLX89e5a8Y0BNH+LOngJyGrIWxG2FKQY=
github.com/tidwall/gjson v1.18.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY=
github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28=
github.com/wI2L/jsondiff v0.6.0 h1:zrsH3FbfVa3JO9llxrcDy/XLkYPLgoMX6Mz3T2PP2AI=
github.com/wI2L/jsondiff v0.6.0/go.mod h1:D6aQ5gKgPF9g17j+E9N7aasmU1O+XvfmWm1y8UMmNpw=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.goms.io/fleet-networking v0.2.7 h1:lVs2/GiCjo18BRgACib+VPnENUMh+2YbYXoeNtcAvw0=
go.goms.io/fleet-networking v0.2.7/go.mod h1:JoWG82La5nV29mooOnPpIhy6/Pi4oGXQk21CPF1UStg=
go.goms.io/fleet-networking v0.2.11 h1:N5/5TckwEipA8s4DC71lzwdz88P3mtXdvRKGL8Cg/JA=
go.goms.io/fleet-networking v0.2.11/go.mod h1:tenpiBceno4hiCakjCMz/KCAwRlBz0+/kER6lSXy+Mk=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.52.0 h1:9l89oX4ba9kHbBol3Xin3leYJ+252h0zszDtBwyKe2A=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.52.0/go.mod h1:XLZfZboOJWHNKUv7eH0inh0E9VV6eWDFB/9yJyTLPp0=
go.opentelemetry.io/otel v1.31.0 h1:NsJcKPIW0D0H3NgzPDHmo0WW6SptzPdqg/L1zsIm2hY=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,13 @@ func TestValidateEviction(t *testing.T) {
Client: fakeClient,
}
gotValidationResult, gotErr := r.validateEviction(ctx, tc.eviction)

// Since default values are applied to the affected CRP in the eviction controller; the
// the same must be done on the expected result as well.
if tc.wantValidationResult.crp != nil {
defaulter.SetDefaultsClusterResourcePlacement(tc.wantValidationResult.crp)
}

if diff := cmp.Diff(tc.wantValidationResult, gotValidationResult, validationResultCmpOptions...); diff != "" {
t.Errorf("validateEviction() validation result mismatch (-want, +got):\n%s", diff)
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/controllers/work/applier.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ func findConflictedWork(ctx context.Context, hubClient client.Client, namespace
// * the defaulting webhook failure policy is configured as "fail".
// * user cannot update/delete the webhook.
defaulter.SetDefaultsWork(work)
// Note (chenyu1): set the defaults here to accommodate for new apply strategy fields added in v1beta1
// API version.
defaulter.SetDefaultsApplyStrategy(strategy)
if !equality.Semantic.DeepEqual(strategy, work.Spec.ApplyStrategy) {
return work, nil
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/controllers/work/apply_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,10 @@ func trackResourceAvailability(gvr schema.GroupVersionResource, curObj *unstruct
case utils.DeploymentGVR:
return trackDeploymentAvailability(curObj)

case utils.StatefulSettGVR:
case utils.StatefulSetGVR:
return trackStatefulSetAvailability(curObj)

case utils.DaemonSettGVR:
case utils.DaemonSetGVR:
return trackDaemonSetAvailability(curObj)

case utils.ServiceGVR:
Expand Down
12 changes: 6 additions & 6 deletions pkg/controllers/work/apply_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,7 @@ func TestTrackResourceAvailability(t *testing.T) {
err: nil,
},
"Test StatefulSet available": {
gvr: utils.StatefulSettGVR,
gvr: utils.StatefulSetGVR,
obj: &unstructured.Unstructured{
Object: map[string]interface{}{
"apiVersion": "apps/v1",
Expand All @@ -1049,7 +1049,7 @@ func TestTrackResourceAvailability(t *testing.T) {
err: nil,
},
"Test StatefulSet not available": {
gvr: utils.StatefulSettGVR,
gvr: utils.StatefulSetGVR,
obj: &unstructured.Unstructured{
Object: map[string]interface{}{
"apiVersion": "apps/v1",
Expand All @@ -1073,7 +1073,7 @@ func TestTrackResourceAvailability(t *testing.T) {
err: nil,
},
"Test StatefulSet observed old generation": {
gvr: utils.StatefulSettGVR,
gvr: utils.StatefulSetGVR,
obj: &unstructured.Unstructured{
Object: map[string]interface{}{
"apiVersion": "apps/v1",
Expand All @@ -1097,7 +1097,7 @@ func TestTrackResourceAvailability(t *testing.T) {
err: nil,
},
"Test DaemonSet Available": {
gvr: utils.DaemonSettGVR,
gvr: utils.DaemonSetGVR,
obj: &unstructured.Unstructured{
Object: map[string]interface{}{
"apiVersion": "apps/v1",
Expand All @@ -1118,7 +1118,7 @@ func TestTrackResourceAvailability(t *testing.T) {
err: nil,
},
"Test DaemonSet not available": {
gvr: utils.DaemonSettGVR,
gvr: utils.DaemonSetGVR,
obj: &unstructured.Unstructured{
Object: map[string]interface{}{
"apiVersion": "apps/v1",
Expand All @@ -1139,7 +1139,7 @@ func TestTrackResourceAvailability(t *testing.T) {
err: nil,
},
"Test DaemonSet not observe current generation": {
gvr: utils.DaemonSettGVR,
gvr: utils.DaemonSetGVR,
obj: &unstructured.Unstructured{
Object: map[string]interface{}{
"apiVersion": "apps/v1",
Expand Down
Loading
Loading