@@ -50,21 +50,29 @@ func (s *StringList) Set(value string) error {
5050
5151var (
5252 crdsDir StringList
53+ crds StringList
5354)
5455
5556func initFlags () {
5657 flag .Var (& crdsDir , "crds-dir" , "Path to the directory containing the CRD manifests" )
58+ flag .Var (& crds , "crds-file" , "Single CRDs file with CRD manifests to apply" )
5759 flag .Parse ()
5860
59- if len (crdsDir ) == 0 {
60- log .Fatalf ("CRDs directory is required" )
61+ if len (crdsDir ) == 0 && len ( crds ) == 0 {
62+ log .Fatalf ("CRDs directory or single CRDs are required" )
6163 }
6264
6365 for _ , crdDir := range crdsDir {
6466 if _ , err := os .Stat (crdDir ); os .IsNotExist (err ) {
6567 log .Fatalf ("CRDs directory %s does not exist" , crdsDir )
6668 }
6769 }
70+
71+ for _ , crd := range crds {
72+ if _ , err := os .Stat (crd ); os .IsNotExist (err ) {
73+ log .Fatalf ("CRD file %s does not exist" , crd )
74+ }
75+ }
6876}
6977
7078// EnsureCRDsCmd reads each YAML file in the directory, splits it into documents, and applies each CRD to the cluster.
@@ -87,6 +95,10 @@ func EnsureCRDsCmd() {
8795 if err := walkCrdsDir (ctx , client .ApiextensionsV1 ().CustomResourceDefinitions ()); err != nil {
8896 log .Fatalf ("Failed to apply CRDs: %v" , err )
8997 }
98+
99+ if err := applyCrdFiles (ctx , client .ApiextensionsV1 ().CustomResourceDefinitions ()); err != nil {
100+ log .Fatalf ("Failed to apply CRDs: %v" , err )
101+ }
90102}
91103
92104// walkCrdsDir walks the CRDs directory and applies each YAML file.
@@ -114,6 +126,16 @@ func walkCrdsDir(ctx context.Context, crdClient v1.CustomResourceDefinitionInter
114126 return nil
115127}
116128
129+ func applyCrdFiles (ctx context.Context , crdClient v1.CustomResourceDefinitionInterface ) error {
130+ for _ , crdFile := range crds {
131+ log .Printf ("Apply CRDs from file: %s" , crdFile )
132+ if err := applyCRDsFromFile (ctx , crdClient , crdFile ); err != nil {
133+ return fmt .Errorf ("apply CRD %s: %w" , crdFile , err )
134+ }
135+ }
136+ return nil
137+ }
138+
117139// applyCRDsFromFile reads a YAML file, splits it into documents, and applies each CRD to the cluster.
118140func applyCRDsFromFile (ctx context.Context , crdClient v1.CustomResourceDefinitionInterface , filePath string ) error {
119141 file , err := os .Open (filePath )
0 commit comments