Skip to content
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
15 changes: 8 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ require (
k8s.io/component-base v0.32.4
k8s.io/klog/v2 v2.130.1
k8s.io/utils v0.0.0-20241210054802-24370beab758
open-cluster-management.io/api v0.16.2-0.20250527062515-98a1d87193c1
open-cluster-management.io/api v1.0.1-0.20250722080758-779879f46835
sigs.k8s.io/controller-runtime v0.20.2
)

Expand All @@ -39,7 +39,7 @@ require (
github.com/openshift/hypershift/api v0.0.0-20241022184855-1fa7be0211e4
github.com/sethvargo/go-password v0.2.0
github.com/stretchr/testify v1.10.0
open-cluster-management.io/ocm v0.16.1-0.20250527120941-4cbb12d5a262
open-cluster-management.io/ocm v1.0.1-0.20250724011102-334710ce0e60
sigs.k8s.io/cluster-api v1.9.3
sigs.k8s.io/yaml v1.4.0
)
Expand Down Expand Up @@ -81,7 +81,7 @@ require (
github.com/golang/glog v1.2.4 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/btree v1.1.3 // indirect
github.com/google/gnostic-models v0.6.9-0.20230804172637-c7be7c783f49 // indirect
github.com/google/gnostic-models v0.6.9 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/pprof v0.0.0-20250403155104-27863c87afa6 // indirect
github.com/google/uuid v1.6.0 // indirect
Expand Down Expand Up @@ -133,8 +133,8 @@ require (
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
go.mongodb.org/mongo-driver v1.14.0 // indirect
go.opentelemetry.io/otel v1.28.0 // indirect
go.opentelemetry.io/otel/trace v1.28.0 // indirect
go.opentelemetry.io/otel v1.33.0 // indirect
go.opentelemetry.io/otel/trace v1.33.0 // indirect
go.uber.org/automaxprocs v1.6.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.41.0 // indirect
Expand All @@ -143,7 +143,7 @@ require (
golang.org/x/sync v0.16.0 // indirect
golang.org/x/sys v0.35.0 // indirect
golang.org/x/term v0.34.0 // indirect
golang.org/x/time v0.7.0 // indirect
golang.org/x/time v0.9.0 // indirect
golang.org/x/tools v0.35.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/protobuf v1.36.5 // indirect
Expand All @@ -154,9 +154,10 @@ require (
gorm.io/gorm v1.24.5 // indirect
helm.sh/helm/v3 v3.17.4 // indirect
k8s.io/kube-aggregator v0.32.1 // indirect
k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f // indirect
k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff // indirect
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 // indirect
sigs.k8s.io/kube-storage-version-migrator v0.0.6-0.20230721195810-5c8923c5ff96 // indirect
sigs.k8s.io/randfill v1.0.0 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.6.0 // indirect
)

Expand Down
31 changes: 16 additions & 15 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/google/btree v1.1.3 h1:CVpQJjYgC4VbzxeGVHfvZrv1ctoYCAI8vbl07Fcxlyg=
github.com/google/btree v1.1.3/go.mod h1:qOPhT0dTNdNzV6Z/lhRX0YXUafgPLFUh+gZMl761Gm4=
github.com/google/gnostic-models v0.6.9-0.20230804172637-c7be7c783f49 h1:0VpGH+cDhbDtdcweoyCVsF3fhN8kejK6rFe/2FFX2nU=
github.com/google/gnostic-models v0.6.9-0.20230804172637-c7be7c783f49/go.mod h1:BkkQ4L1KS1xMt2aWSPStnn55ChGC0DPOn2FQYj+f25M=
github.com/google/gnostic-models v0.6.9 h1:MU/8wDLif2qCXZmzncUQ/BOfxWfthHi63KqpoNbWqVw=
github.com/google/gnostic-models v0.6.9/go.mod h1:CiWsm0s6BSQd1hRn8/QmxqB6BesYcbSZxsz9b0KuDBw=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
Expand Down Expand Up @@ -429,10 +429,10 @@ github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1
github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
go.mongodb.org/mongo-driver v1.14.0 h1:P98w8egYRjYe3XDjxhYJagTokP/H6HzlsnojRgZRd80=
go.mongodb.org/mongo-driver v1.14.0/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGcNU603k65c=
go.opentelemetry.io/otel v1.28.0 h1:/SqNcYk+idO0CxKEUOtKQClMK/MimZihKYMruSMViUo=
go.opentelemetry.io/otel v1.28.0/go.mod h1:q68ijF8Fc8CnMHKyzqL6akLO46ePnjkgfIMIjUIX9z4=
go.opentelemetry.io/otel/trace v1.28.0 h1:GhQ9cUuQGmNDd5BTCP2dAvv75RdMxEfTmYejp+lkx9g=
go.opentelemetry.io/otel/trace v1.28.0/go.mod h1:jPyXzNPg6da9+38HEwElrQiHlVMTnVfM3/yv2OlIHaI=
go.opentelemetry.io/otel v1.33.0 h1:/FerN9bax5LoK51X/sI0SVYrjSE0/yUL7DpxW4K3FWw=
go.opentelemetry.io/otel v1.33.0/go.mod h1:SUUkR6csvUQl+yjReHu5uM3EtVV7MBm5FHKRlNx4I8I=
go.opentelemetry.io/otel/trace v1.33.0 h1:cCJuF7LRjUFso9LPnEAHJDB2pqzp+hbO8eu1qqW2d/s=
go.opentelemetry.io/otel/trace v1.33.0/go.mod h1:uIcdVUZMpTAmz0tI1z04GoVSezK37CbGV4fr1f2nBck=
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
Expand Down Expand Up @@ -556,8 +556,8 @@ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng=
golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU=
golang.org/x/time v0.7.0 h1:ntUhktv3OPE6TgYxXWv9vKvUSJyIFJlyohwbkEwPrKQ=
golang.org/x/time v0.7.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
golang.org/x/time v0.9.0 h1:EsRrnYcQiGH+5FfbgvV4AP7qEZstoyrHB0DzarOQ4ZY=
golang.org/x/time v0.9.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
Expand Down Expand Up @@ -670,16 +670,16 @@ k8s.io/kube-aggregator v0.32.1 h1:cztPyIHbo6tgrhYHDqmdmvxUufJKuxgAC/vog7yeWek=
k8s.io/kube-aggregator v0.32.1/go.mod h1:sXjL5T8FO/rlBzTbBhahw9V5Nnr1UtzZHKTj9WxQCOU=
k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65/go.mod h1:sX9MT8g7NVZM5lVL/j8QyCCJe8YSMW30QvGZWaCIDIk=
k8s.io/kube-openapi v0.0.0-20220124234850-424119656bbf/go.mod h1:sX9MT8g7NVZM5lVL/j8QyCCJe8YSMW30QvGZWaCIDIk=
k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f h1:GA7//TjRY9yWGy1poLzYYJJ4JRdzg3+O6e8I+e+8T5Y=
k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f/go.mod h1:R/HEjbvWI0qdfb8viZUeVZm0X6IZnxAydC7YU42CMw4=
k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff h1:/usPimJzUKKu+m+TE36gUyGcf03XZEP0ZIKgKj35LS4=
k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff/go.mod h1:5jIi+8yX4RIb8wk3XwBo5Pq2ccx4FP10ohkbSKCZoK8=
k8s.io/utils v0.0.0-20210802155522-efc7438f0176/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
k8s.io/utils v0.0.0-20211116205334-6203023598ed/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
k8s.io/utils v0.0.0-20241210054802-24370beab758 h1:sdbE21q2nlQtFh65saZY+rRM6x6aJJI8IUa1AmH/qa0=
k8s.io/utils v0.0.0-20241210054802-24370beab758/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
open-cluster-management.io/api v0.16.2-0.20250527062515-98a1d87193c1 h1:OAFgR9hrr3dpiwb+Pgz5gSKKdtnHwD8L+PkBd4HjHXc=
open-cluster-management.io/api v0.16.2-0.20250527062515-98a1d87193c1/go.mod h1:/OeqXycNBZQoe3WG6ghuWsMgsKGuMZrK8ZpsU6gWL0Y=
open-cluster-management.io/ocm v0.16.1-0.20250527120941-4cbb12d5a262 h1:lcaj0Ep+TOBPkE19u0Qiqu2d05pSrjDpqd7sF6lc8L8=
open-cluster-management.io/ocm v0.16.1-0.20250527120941-4cbb12d5a262/go.mod h1:60fdcsEXEMe9sPag8R+a/VEwdmxIsh9VsnnWdmUtfA8=
open-cluster-management.io/api v1.0.1-0.20250722080758-779879f46835 h1:am2IzUzjoTjgiicbCfzl7dTITdTo1PtcTuYX0P5KZ2I=
open-cluster-management.io/api v1.0.1-0.20250722080758-779879f46835/go.mod h1:KEj/4wbUjdbWktrKLL8+mWzAIzE6Ii3bcRr4CvnBNEg=
open-cluster-management.io/ocm v1.0.1-0.20250724011102-334710ce0e60 h1:bsHrwWYW5e0q5w9NovDeM9b4K9LqBnJMHXucKeUfOGA=
open-cluster-management.io/ocm v1.0.1-0.20250724011102-334710ce0e60/go.mod h1:qxwXm6Z3OCDUUDznLmQVWk5A3CrHiE1G+TJ56DF+DXs=
sigs.k8s.io/cluster-api v1.9.3 h1:lKWbrXzyNmJh++IcX54ZbAmnO7tZ2wKgds7WvskpiXY=
sigs.k8s.io/cluster-api v1.9.3/go.mod h1:5iojv38PSvOd4cxqu08Un5TQmy2yBkd3+0U7R/e+msk=
sigs.k8s.io/controller-runtime v0.20.2 h1:/439OZVxoEc02psi1h4QO3bHzTgu49bb347Xp4gW1pc=
Expand All @@ -689,8 +689,9 @@ sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 h1:gBQPwqORJ8d8/YNZWEjoZs7np
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8/go.mod h1:mdzfpAEoE6DHQEN0uh9ZbOCuHbLK5wOm7dK4ctXE9Tg=
sigs.k8s.io/kube-storage-version-migrator v0.0.6-0.20230721195810-5c8923c5ff96 h1:PFWFSkpArPNJxFX4ZKWAk9NSeRoZaXschn+ULa4xVek=
sigs.k8s.io/kube-storage-version-migrator v0.0.6-0.20230721195810-5c8923c5ff96/go.mod h1:EOBQyBowOUsd7U4CJnMHNE0ri+zCXyouGdLwC/jZU+I=
sigs.k8s.io/randfill v0.0.0-20250304075658-069ef1bbf016 h1:kXv6kKdoEtedwuqMmkqhbkgvYKeycVbC8+iPCP9j5kQ=
sigs.k8s.io/randfill v0.0.0-20250304075658-069ef1bbf016/go.mod h1:XeLlZ/jmk4i1HRopwe7/aU3H5n1zNUcX6TM94b3QxOY=
sigs.k8s.io/randfill v1.0.0 h1:JfjMILfT8A6RbawdsK2JXGBR5AQVfd+9TbzrlneTyrU=
sigs.k8s.io/randfill v1.0.0/go.mod h1:XeLlZ/jmk4i1HRopwe7/aU3H5n1zNUcX6TM94b3QxOY=
sigs.k8s.io/structured-merge-diff/v4 v4.0.2/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK1F7G282QMXDPYydCw=
sigs.k8s.io/structured-merge-diff/v4 v4.2.1/go.mod h1:j/nl6xW8vLS49O8YvXW1ocPhZawJtm+Yrr7PPRQ0Vg4=
sigs.k8s.io/structured-merge-diff/v4 v4.6.0 h1:IUA9nvMmnKWcj5jl84xn+T5MnlZKThmUW1TdblaLVAc=
Expand Down
6 changes: 5 additions & 1 deletion pkg/controller/resourcecleanup/resourcecleanup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
utilerrors "k8s.io/apimachinery/pkg/util/errors"
kevents "k8s.io/client-go/tools/events"
clusterv1 "open-cluster-management.io/api/cluster/v1"
workv1 "open-cluster-management.io/api/work/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
Expand Down Expand Up @@ -252,9 +253,12 @@ func (r *ReconcileResourceCleanup) Cleanup(ctx context.Context, cluster *cluster
if len(works.Items) == 1 && works.Items[0].Name == klusterletCRDWorkName {
// the manifestWorks are deleted by registration controller.
// the agent may be orphaned if the CRD manifestWork is force deleted directly.
if works.Items[0].DeletionTimestamp.IsZero() {
// so the crd is deleting when the deleting condition of crd work is true
// and can force delete the crd work after the crd work is deleting.
if !meta.IsStatusConditionTrue(works.Items[0].Status.Conditions, workv1.WorkDeleting) {
return nil
}

if err = helpers.ForceDeleteManifestWork(ctx, r.clientHolder.WorkClient, r.recorder,
cluster.Name, klusterletCRDWorkName); err != nil {
return err
Expand Down
96 changes: 90 additions & 6 deletions pkg/controller/resourcecleanup/resourcecleanup_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func TestReconcile(t *testing.T) {
},
},
{
name: "default cluster is deleting and have klustereletCRD work",
name: "default cluster is deleting and klustereletCRD work is not deleting and no finalizer",
request: reconcile.Request{NamespacedName: types.NamespacedName{Name: "test"}},
runtimeObjects: []client.Object{
&clusterv1.ManagedCluster{
Expand All @@ -95,17 +95,101 @@ func TestReconcile(t *testing.T) {
&corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: "test"}},
},
works: []runtime.Object{
&workv1.ManifestWork{ObjectMeta: metav1.ObjectMeta{
Name: "test-klusterlet-crds",
Namespace: "test",
DeletionTimestamp: &now}},
&workv1.ManifestWork{
ObjectMeta: metav1.ObjectMeta{
Name: "test-klusterlet-crds",
Namespace: "test",
},
},
},
requeue: true,
validateFunc: func(t *testing.T, clientHolder *helpers.ClientHolder) {
managedCluster := &clusterv1.ManagedCluster{}
if err := clientHolder.RuntimeClient.Get(context.TODO(),
types.NamespacedName{Name: "test"}, managedCluster); errors.IsNotFound(err) {
t.Errorf("unexpected no cluster,but got error: %v", err)
}
},
},
{
name: "default cluster is deleting and klustereletCRD work is deleting",
request: reconcile.Request{NamespacedName: types.NamespacedName{Name: "test"}},
runtimeObjects: []client.Object{
&clusterv1.ManagedCluster{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Finalizers: []string{constants.ImportFinalizer, constants.ManifestWorkFinalizer},
DeletionTimestamp: &now,
},
Spec: clusterv1.ManagedClusterSpec{
HubAcceptsClient: true,
},
},
},
kubeObjects: []runtime.Object{
&corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: "test"}},
},
works: []runtime.Object{
&workv1.ManifestWork{
ObjectMeta: metav1.ObjectMeta{
Name: "test-klusterlet-crds",
Namespace: "test",
DeletionTimestamp: &now,
Finalizers: []string{workv1.ManifestWorkFinalizer},
},
},
},
requeue: true,
validateFunc: func(t *testing.T, clientHolder *helpers.ClientHolder) {
managedCluster := &clusterv1.ManagedCluster{}
if err := clientHolder.RuntimeClient.Get(context.TODO(),
types.NamespacedName{Name: "test"}, managedCluster); errors.IsNotFound(err) {
t.Errorf("unexpected no cluster,but got error: %v", err)
}
},
},
{
name: "default cluster is deleting and klustereletCRD work is deleting and have deleting condition",
request: reconcile.Request{NamespacedName: types.NamespacedName{Name: "test"}},
runtimeObjects: []client.Object{
&clusterv1.ManagedCluster{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Finalizers: []string{constants.ImportFinalizer, constants.ManifestWorkFinalizer},
DeletionTimestamp: &now,
},
Spec: clusterv1.ManagedClusterSpec{
HubAcceptsClient: true,
},
},
},
kubeObjects: []runtime.Object{
&corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: "test"}},
},
works: []runtime.Object{
&workv1.ManifestWork{
ObjectMeta: metav1.ObjectMeta{
Name: "test-klusterlet-crds",
Namespace: "test",
DeletionTimestamp: &now,
Finalizers: []string{workv1.ManifestWorkFinalizer},
},
Status: workv1.ManifestWorkStatus{
Conditions: []metav1.Condition{
metav1.Condition{
Type: workv1.WorkDeleting,
Status: metav1.ConditionTrue,
},
},
},
},
},
requeue: false,
validateFunc: func(t *testing.T, clientHolder *helpers.ClientHolder) {
managedCluster := &clusterv1.ManagedCluster{}
if err := clientHolder.RuntimeClient.Get(context.TODO(),
types.NamespacedName{Name: "test"}, managedCluster); !errors.IsNotFound(err) {
t.Errorf("unexpected no cluster,but got error: %v", err)
t.Errorf("expected no cluster,but got error: %v", err)
}
},
},
Expand Down
Loading
Loading