@@ -26,13 +26,15 @@ import (
26
26
"github.com/rook/kubectl-rook-ceph/pkg/k8sutil"
27
27
"github.com/rook/kubectl-rook-ceph/pkg/logging"
28
28
apierrors "k8s.io/apimachinery/pkg/api/errors"
29
+ "k8s.io/apimachinery/pkg/runtime/schema"
29
30
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
30
31
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
31
32
"k8s.io/apimachinery/pkg/types"
32
33
)
33
34
34
35
func RestoreCrdNew (ctx context.Context , k8sclientset * k8sutil.Clientsets , operatorNamespace , clusterNamespace ,
35
36
groupName , versionResource string , args []string ) {
37
+
36
38
crd := args [0 ]
37
39
38
40
var crName string
@@ -125,6 +127,86 @@ func RestoreCrdNew(ctx context.Context, k8sclientset *k8sutil.Clientsets, operat
125
127
func removeOwnerRefOfUID (ctx context.Context , k8sclientset * k8sutil.Clientsets , operatorNamespace , clusterNamespace , targetUID string ) {
126
128
logging .Info ("Removing ownerreferences from resources with matching uid %s" , targetUID )
127
129
130
+ customResources := []struct {
131
+ group string
132
+ version string
133
+ resource string
134
+ }{
135
+ // ceph.rook.io/v1
136
+ {"ceph.rook.io" , "v1" , "cephblockpoolradosnamespaces" },
137
+ {"ceph.rook.io" , "v1" , "cephblockpools" },
138
+ {"ceph.rook.io" , "v1" , "cephbucketnotifications" },
139
+ {"ceph.rook.io" , "v1" , "cephbuckettopics" },
140
+ {"ceph.rook.io" , "v1" , "cephclients" },
141
+ {"ceph.rook.io" , "v1" , "cephclusters" },
142
+ {"ceph.rook.io" , "v1" , "cephcosidrivers" },
143
+ {"ceph.rook.io" , "v1" , "cephfilesystemmirrors" },
144
+ {"ceph.rook.io" , "v1" , "cephfilesystems" },
145
+ {"ceph.rook.io" , "v1" , "cephfilesystemsubvolumegroups" },
146
+ {"ceph.rook.io" , "v1" , "cephnfses" },
147
+ {"ceph.rook.io" , "v1" , "cephobjectrealms" },
148
+ {"ceph.rook.io" , "v1" , "cephobjectstores" },
149
+ {"ceph.rook.io" , "v1" , "cephobjectstoreusers" },
150
+ {"ceph.rook.io" , "v1" , "cephobjectzonegroups" },
151
+ {"ceph.rook.io" , "v1" , "cephobjectzones" },
152
+ {"ceph.rook.io" , "v1" , "cephrbdmirrors" },
153
+
154
+ // noobaa.io/v1alpha1
155
+ {"noobaa.io" , "v1alpha1" , "backingstores" },
156
+ {"noobaa.io" , "v1alpha1" , "bucketclasses" },
157
+ {"noobaa.io" , "v1alpha1" , "namespacestores" },
158
+ {"noobaa.io" , "v1alpha1" , "noobaaaccounts" },
159
+ {"noobaa.io" , "v1alpha1" , "noobaas" },
160
+
161
+ // postgresql.cnpg.noobaa.io/v1alpha1
162
+ {"postgresql.cnpg.noobaa.io" , "v1alpha1" , "backups" },
163
+ {"postgresql.cnpg.noobaa.io" , "v1alpha1" , "clusterimagecatalogs" },
164
+ {"postgresql.cnpg.noobaa.io" , "v1alpha1" , "clusters" },
165
+ {"postgresql.cnpg.noobaa.io" , "v1alpha1" , "databases" },
166
+ {"postgresql.cnpg.noobaa.io" , "v1alpha1" , "imagecatalogs" },
167
+ {"postgresql.cnpg.noobaa.io" , "v1alpha1" , "poolers" },
168
+ {"postgresql.cnpg.noobaa.io" , "v1alpha1" , "publications" },
169
+ {"postgresql.cnpg.noobaa.io" , "v1alpha1" , "scheduledbackups" },
170
+ {"postgresql.cnpg.noobaa.io" , "v1alpha1" , "subscriptions" },
171
+ }
172
+ for _ , crd := range customResources {
173
+ gvr := schema.GroupVersionResource {
174
+ Group : crd .group ,
175
+ Version : crd .version ,
176
+ Resource : crd .resource ,
177
+ }
178
+
179
+ crList , err := k8sclientset .ListResourcesDynamically (ctx , crd .group , crd .version , crd .resource , clusterNamespace )
180
+ if err != nil {
181
+ logging .Warning ("Failed to list %s: %v" , crd .resource , err )
182
+ continue
183
+ }
184
+
185
+ for _ , cr := range crList {
186
+ updated := false
187
+ owners := cr .GetOwnerReferences ()
188
+ newOwners := []v1.OwnerReference {}
189
+
190
+ for _ , owner := range owners {
191
+ if string (owner .UID ) != targetUID {
192
+ newOwners = append (newOwners , owner )
193
+ } else {
194
+ updated = true
195
+ }
196
+ }
197
+
198
+ if updated {
199
+ logging .Info ("Removing ownerReference for %s/%s" , crd .resource , cr .GetName ())
200
+ cr .SetOwnerReferences (newOwners )
201
+
202
+ _ , err := k8sclientset .Dynamic .Resource (gvr ).Namespace (clusterNamespace ).Update (ctx , & cr , v1.UpdateOptions {})
203
+ if err != nil {
204
+ logging .Fatal (fmt .Errorf ("Failed to update ownerReferences for %s/%s: %v" , crd .resource , cr .GetName (), err ))
205
+ }
206
+ }
207
+ }
208
+ }
209
+
128
210
secrets , err := k8sclientset .Kube .CoreV1 ().Secrets (clusterNamespace ).List (ctx , v1.ListOptions {})
129
211
if err != nil {
130
212
logging .Fatal (errors .Wrapf (err , "Failed to list secrets" ))
@@ -234,4 +316,5 @@ func removeOwnerRefOfUID(ctx context.Context, k8sclientset *k8sutil.Clientsets,
234
316
}
235
317
}
236
318
}
319
+
237
320
}
0 commit comments