Skip to content

Commit 99b6929

Browse files
author
Arvind Thirumurugan
committed
add scheme to client
1 parent 4919eaf commit 99b6929

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

cmd/crdinstaller/main.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,14 @@ func main() {
105105
// Get Kubernetes config using controller-runtime.
106106
config := ctrl.GetConfigOrDie()
107107

108-
client, err := client.New(config, client.Options{})
108+
// Create a scheme that knows about CRD types.
109+
scheme := runtime.NewScheme()
110+
if err := apiextensionsv1.AddToScheme(scheme); err != nil {
111+
klog.Fatalf("Failed to add apiextensions scheme: %v", err)
112+
}
113+
client, err := client.New(config, client.Options{
114+
Scheme: scheme,
115+
})
109116

110117
if err != nil {
111118
klog.Fatalf("Failed to create Kubernetes client: %v", err)
@@ -179,14 +186,8 @@ func installCRDs(ctx context.Context, client client.Client, crdPath, mode string
179186
return fmt.Errorf("failed to read CRD file %s: %w", path, err)
180187
}
181188

182-
// Create a scheme that knows about CRD types.
183-
scheme := runtime.NewScheme()
184-
if err := apiextensionsv1.AddToScheme(scheme); err != nil {
185-
return fmt.Errorf("failed to add apiextensions scheme: %w", err)
186-
}
187-
188189
// Create decoder for converting raw bytes to Go types.
189-
codecFactory := serializer.NewCodecFactory(scheme)
190+
codecFactory := serializer.NewCodecFactory(client.Scheme())
190191
decoder := codecFactory.UniversalDeserializer()
191192

192193
// Decode YAML into a structured CRD object.
@@ -212,6 +213,13 @@ func installCRDs(ctx context.Context, client client.Client, crdPath, mode string
212213
// Copy spec from our decoded CRD to the object we're creating/updating.
213214
existingCRD.Spec = crd.Spec
214215
existingCRD.SetLabels(crd.Labels)
216+
217+
// Add an additional ownership label to indicate this CRD is managed by the installer.
218+
if existingCRD.Labels == nil {
219+
existingCRD.Labels = make(map[string]string)
220+
}
221+
existingCRD.Labels["crd-installer.kubernetes-fleet.io/managed"] = "true"
222+
215223
existingCRD.SetAnnotations(crd.Annotations)
216224
return nil
217225
})

0 commit comments

Comments
 (0)