kubestellar / kubeflex

A flexible and scalable platform for running Kubernetes control plane APIs.
Apache License 2.0
46 stars 13 forks source link

bug: `kflex create -p garbage` claims success #235

Closed MikeSpreitzer closed 4 months ago

MikeSpreitzer commented 4 months ago

Describe the bug

kflex create claims success when told to use a PostCreateHook that does not exist. The following typescript shows an example.

mspreitz@mjs13 kubestellar % kubectl --context kind-kubeflex get pch
NAME             SYNCED   READY   TYPE   AGE
openshift-crds                           5m49s

mspreitz@mjs13 kubestellar % kflex create its2 --type vcluster -p flagrant-garbage
✔ Checking for saved initial context...
✔ Switching to initial context...
✔ Creating new control plane its2 of type vcluster ...
✔ Waiting for API server to become ready...

mspreitz@mjs13 kubestellar % echo $?
0

Steps To Reproduce

Shown above.

Expected Behavior

Error message and non-zero exit status in this case.

Additional Context

https://github.com/kubestellar/kubestellar/issues/2069

pdettori commented 4 months ago

Note that success is claimed because the control plane does get created. What is not successful is applying the PCH, which comes after. The status for the control planes reflects the outcome of applying the PCH:

$ kubectl get cp its2
NAME   SYNCED   READY   TYPE       AGE
its2   False    True    vcluster   9m40s

and you can see more in detail the problem here:

$ kubectl describe cp its2
Name:         its2
Namespace:    
Labels:       <none>
Annotations:  <none>
API Version:  tenancy.kflex.kubestellar.org/v1alpha1
Kind:         ControlPlane
Metadata:
  Creation Timestamp:  2024-04-23T13:52:02Z
  Finalizers:
    kflex.kubestellar.org/finalizer
  Generation:        1
  Resource Version:  1717699
  UID:               88383724-77b3-4c55-9066-e3def75270d9
Spec:
  Backend:           shared
  Post Create Hook:  flagrant-garbage
  Type:              vcluster
Status:
  Conditions:
    Last Transition Time:  2024-04-23T13:53:02Z
    Last Update Time:      2024-04-23T13:53:02Z
    Message:               
    Reason:                Available
    Status:                True
    Type:                  Ready
    Last Transition Time:  2024-04-23T13:53:02Z
    Last Update Time:      2024-04-23T13:53:02Z
    Message:               error retrieving post create hook flagrant-garbage PostCreateHook.tenancy.kflex.kubestellar.org "flagrant-garbage" not found
    Reason:                ReconcileError
    Status:                False
    Type:                  Synced
  Observed Generation:     0
  Secret Ref:
    In Cluster Key:  config-incluster
    Key:             config
    Name:            vc-vcluster
    Namespace:       its2-system
Events:              <none>

I may be wrong, but since all kflex create is doing here is generating the yaml for the control plane (with the PCH set) the behavior should be somehow consistent with kubectl create -f - if you apply for the example the yaml for a pod that reference a resource that is not there (be that a secret, a config map or service account), you won't get an error from kubectl, but you'll see the problem when you run kubectl get or kubectl describe.

MikeSpreitzer commented 4 months ago

That is a plausible stance. I think it warrants an explicit mention in the User Guide section on PostCreateHooks.

MikeSpreitzer commented 4 months ago

Working as designed.