-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample_import_test.go
54 lines (47 loc) · 1.72 KB
/
example_import_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright (c) 2023 Volvo Car Corporation
// SPDX-License-Identifier: Apache-2.0
package crd_test
import (
"fmt"
"os"
"github.com/golingon/lingon/pkg/kube"
istionetworkingv1beta1 "istio.io/client-go/pkg/apis/networking/v1beta1"
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes/scheme"
secretsstorev1 "sigs.k8s.io/secrets-store-csi-driver/apis/v1"
)
func defaultSerializer() runtime.Decoder {
// Add CRDs to scheme
// This is needed to be able to import CRDs from kubernetes manifests files.
_ = apiextensions.AddToScheme(scheme.Scheme)
_ = apiextensionsv1.AddToScheme(scheme.Scheme)
_ = secretsstorev1.AddToScheme(scheme.Scheme)
_ = istionetworkingv1beta1.AddToScheme(scheme.Scheme)
return scheme.Codecs.UniversalDeserializer()
}
// Example_import to shows how to import CRDs from kubernetes manifests files.
func Example_import() {
// Remove previously generated output directory
_ = os.RemoveAll("./out")
err := kube.Import(
kube.WithImportAppName("team"),
kube.WithImportPackageName("team"),
kube.WithImportManifestFiles([]string{"./manifest.yaml"}),
kube.WithImportOutputDirectory("./out"),
kube.WithImportSerializer(defaultSerializer()),
// do not print verbose information
kube.WithImportVerbose(false),
// do not ignore errors
kube.WithImportIgnoreErrors(false),
// use the default logger even if unused with WithImportVerbose(false)
kube.WithImportLogger(kube.Logger(os.Stderr)),
)
if err != nil {
fmt.Printf("%s\n", err)
}
fmt.Println("successfully imported CRDs from manifest.yaml")
// Output:
// successfully imported CRDs from manifest.yaml
}