-1

I have a Kubernetes project that uses Kustomize functionality. Basically, the directory structure is like follows:

+ base +
+      +- kustomize.yml
+      +- a.yml
+
+ overlays +
           +--- serverA +
                        +- kustomize.yml     
                        + a.yml                    
           +--- serverB +
                        +- kustomize.yml
                

I run "oc apply -k overlays/serverB" and I want it to do an empty run (that is to do nothing; just to skip execution for the server) for serverB. Is it feasible?

Not executing "oc apply -k overlays/serverB" for the server at all is a poor option because I would have to include additional loggic into calling script which I want to avoid.

At the moment I get an error: "error: no objects passed to apply"

1 Answers1

0

This isn't really a kustomize issue; oc apply (and kubectl apply) report that error whenever there are no resources to apply:

$ oc apply -f- < /dev/null
error: no objects passed to apply

You could test if the kustomize directory generates any resources before calling oc apply:

if kustomize build overlays/serverB | grep -q .; then
  oc apply -k overlays/serverB
fi

You could do that for all your overlays, so maybe your script ends up looking something like:

for overlay in overlays/*; do
  if kustomize build $overlay | grep -q .; then
    oc apply -k $overlay
  fi
done
larsks
  • 277,717
  • 41
  • 399
  • 399