spinkube / spin-operator

Spin Operator is a Kubernetes operator that empowers platform engineers to deploy Spin applications as custom resources to their Kubernetes clusters
https://www.spinkube.dev/docs/overview/
Other
185 stars 23 forks source link

SpinApp does not respond to `kubectl scale` #86

Closed bacongobbler closed 8 months ago

bacongobbler commented 8 months ago

Given the following SpinApp:

><> kubectl get spinapp hello-rust -o yaml
apiVersion: core.spinoperator.dev/v1
kind: SpinApp
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"core.spinoperator.dev/v1","kind":"SpinApp","metadata":{"annotations":{},"name":"hello-rust","namespace":"default"},"spec":{"executor":"containerd-shim-spin","image":"bacongobbler/hello-rust:latest","replicas":2}}
  creationTimestamp: "2024-02-20T18:47:21Z"
  generation: 1
  name: hello-rust
  namespace: default
  resourceVersion: "1716"
  uid: 3a4565a9-e0ab-4933-a3ce-eb01b7c908e9
spec:
  checks: {}
  enableAutoscaling: false
  executor: containerd-shim-spin
  image: bacongobbler/hello-rust:latest
  replicas: 2
  resources: {}
  runtimeConfig: {}
status:
  activeScheduler: containerd-shim-spin
  conditions:
  - lastTransitionTime: "2024-02-20T18:49:31Z"
    message: Deployment has minimum availability.
    reason: MinimumReplicasAvailable
    status: "True"
    type: Available
  - lastTransitionTime: "2024-02-20T18:47:21Z"
    message: ReplicaSet "hello-rust-77496795b6" has successfully progressed.
    reason: NewReplicaSetAvailable
    status: "True"
    type: Progressing
  readyReplicas: 2

kubectl get spinapp hello-rust works:

><> kubectl get spinapp hello-rust
NAME         READY REPLICAS   EXECUTOR
hello-rust   2                containerd-shim-spin

But kubectl scale spinapp hello-rust does not.

><> k scale spinapp hello-rust --replicas=3
Error from server (NotFound): spinapps.core.spinoperator.dev "hello-rust" not found
bacongobbler commented 8 months ago

I think this might've been due to the fact that I'm using an outdated fork... Recreating my dev environment to reproduce the issue.

bacongobbler commented 8 months ago

Nope. I was able to reproduce the same issue on main.

><> spin k8s scaffold --from bacongobbler/hello-rust:latest | kubectl apply -f -
spinapp.core.spinoperator.dev/hello-rust created
><> k get spinapps hello-rust -o yaml
apiVersion: core.spinoperator.dev/v1
kind: SpinApp
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"core.spinoperator.dev/v1","kind":"SpinApp","metadata":{"annotations":{},"name":"hello-rust","namespace":"default"},"spec":{"executor":"containerd-shim-spin","image":"bacongobbler/hello-rust:latest","replicas":2}}
  creationTimestamp: "2024-02-20T19:00:11Z"
  generation: 1
  name: hello-rust
  namespace: default
  resourceVersion: "1107"
  uid: c8a32ddf-3ace-4a05-a7ea-c106fd153fa2
spec:
  checks: {}
  enableAutoscaling: false
  executor: containerd-shim-spin
  image: bacongobbler/hello-rust:latest
  replicas: 2
  resources: {}
  runtimeConfig: {}
status:
  activeScheduler: containerd-shim-spin
  conditions:
  - lastTransitionTime: "2024-02-20T19:00:14Z"
    message: Deployment has minimum availability.
    reason: MinimumReplicasAvailable
    status: "True"
    type: Available
  - lastTransitionTime: "2024-02-20T19:00:11Z"
    message: ReplicaSet "hello-rust-77496795b6" has successfully progressed.
    reason: NewReplicaSetAvailable
    status: "True"
    type: Progressing
  readyReplicas: 2
><> k scale spinapp hello-rust --replicas 3
Error from server (NotFound): spinapps.core.spinoperator.dev "hello-rust" not found
endocrimes commented 8 months ago

We don't implement a /scale subresource - we currently have you disable our replicas if you want to integrate with things like HPA.

We could make the SpinApp CR scalable with something like:

// +kubebuilder:subresource:scale:specpath=.spec.replicas,statuspath=.status.readyReplicas,selectorpath=.status.selector

if we published the pod selector in our status too. But this isn't something we've discussed or thought through - I'm not sure how integrating with HPA works metrics wise if you're not a first party k8s component

bacongobbler commented 8 months ago

To be clear, there is an existing workaround. You can change the number of replicas in the manifest and call kubectl apply a second time.

><> spin k8s scaffold --from bacongobbler/hello-rust:latest | kubectl apply -f -
spinapp.core.spinoperator.dev/hello-rust created

><> spin k8s list
NAMESPACE       NAME            EXECUTOR                READY
default         hello-rust      containerd-shim-spin    2/2

><> spin k8s scaffold --from bacongobbler/hello-rust:latest --replicas 3 | kubectl apply -f -
spinapp.core.spinoperator.dev/hello-rust configured

><> spin k8s list
NAMESPACE       NAME            EXECUTOR                READY
default         hello-rust      containerd-shim-spin    3/3
endocrimes commented 8 months ago

Yep! (you can also kubectl edit and update the replicas there)

bacongobbler commented 8 months ago

Can we remove this from the Initial release project board? Doesn't seem totally necessary to solve this issue given that we have several documented workarounds in this thread.

bacongobbler commented 8 months ago

closing as duplicate of https://github.com/spinkube/spin-operator/issues/24.