xcoulon / podset-operator

An example of Kubernetes Operator using the Operator SDK
Apache License 2.0
46 stars 30 forks source link

Status is not shown #2

Open gaurav-dalvi opened 5 years ago

gaurav-dalvi commented 5 years ago

Read your blog : https://medium.com/faun/writing-your-first-kubernetes-operator-8f3df4453234

Excellent starter doc on operator-sdk. Thanks a lot for that. I did exactly the same thing which you did mention in the blog. I am not seeing status being populated in any of the command 1: kubectl describe podsets foo 2: kubectl get podsets -o json Did you face the same issue ?

gaurav-dalvi commented 5 years ago

I fixed it : https://github.com/xcoulon/podset-operator/pull/3

Memcached example has this one: https://github.com/operator-framework/operator-sdk/blob/master/example/memcached-operator/memcached_controller.go.tmpl#L157

gaurav-dalvi commented 5 years ago

Feel free to close it when you verify.

xcoulon commented 5 years ago

@gaurav-dalvi so I tested the PR after merging it, with the latest operator SDK (v0.8.1) and I get the following error in the controller after I created a PodSet CR:

{"level":"error","ts":1559122672.580986,"logger":"kubebuilder.controller","caller":"controller/controller.go:209","msg":"Reconciler error","Controller":"podset-controller","Request":"myproject/example-podset","error":"the server could not find the requested resource (put podsets.app.example.com example-podset)","stacktrace":"github.com/xcoulon/podset-operator/vendor/github.com/go-logr/zapr.(*zapLogger).Error\n\t/Users/xcoulon/code/go/src/github.com/xcoulon/podset-operator/vendor/github.com/go-logr/zapr/zapr.go:128\ngithub.com/xcoulon/podset-operator/vendor/sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem\n\t/Users/xcoulon/code/go/src/github.com/xcoulon/podset-operator/vendor/sigs.k8s.io/controller-runtime/pkg/internal/controller/controller.go:209\ngithub.com/xcoulon/podset-operator/vendor/sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func1\n\t/Users/xcoulon/code/go/src/github.com/xcoulon/podset-operator/vendor/sigs.k8s.io/controller-runtime/pkg/internal/controller/controller.go:157\ngithub.com/xcoulon/podset-operator/vendor/k8s.io/apimachinery/pkg/util/wait.JitterUntil.func1\n\t/Users/xcoulon/code/go/src/github.com/xcoulon/podset-operator/vendor/k8s.io/apimachinery/pkg/util/wait/wait.go:133\ngithub.com/xcoulon/podset-operator/vendor/k8s.io/apimachinery/pkg/util/wait.JitterUntil\n\t/Users/xcoulon/code/go/src/github.com/xcoulon/podset-operator/vendor/k8s.io/apimachinery/pkg/util/wait/wait.go:134\ngithub.com/xcoulon/podset-operator/vendor/k8s.io/apimachinery/pkg/util/wait.Until\n\t/Users/xcoulon/code/go/src/github.com/xcoulon/podset-operator/vendor/k8s.io/apimachinery/pkg/util/wait/wait.go:88"}

I'm going to revert your PR (I should have tested it before merging 😕)

Also: I've pushed the latest Docker image (ie, without your patch) to Quay.io: https://quay.io/repository/xcoulon/podset-operator?tab=tags

On Minishift, I run the following commands:

$ oc create -f deploy/operator.yaml

$ echo "apiVersion: app.example.com/v1alpha1
kind: PodSet
metadata:
  name: example-podset
spec:
  replicas: 3" | oc create -f -

and at this point, the 3 expected pods are immediately created:

$ oc get pods
NAME                               READY     STATUS              RESTARTS   AGE
example-podset-podnvlcs            0/1       ContainerCreating   0          3s
example-podset-podtvgsf            0/1       ContainerCreating   0          3s
example-podset-podzv475            0/1       ContainerCreating   0          3s
podset-operator-685bbbc858-2ccvd   1/1       Running             0          2m

and I can check the status of the podset to see the associated/child pods:

$ oc describe podset example-podset
Name:         example-podset
Namespace:    myproject
Labels:       <none>
Annotations:  <none>
API Version:  app.example.com/v1alpha1
Kind:         PodSet
Metadata:
  Creation Timestamp:  2019-05-29T09:50:12Z
  Generation:          1
  Resource Version:    16067
  Self Link:           /apis/app.example.com/v1alpha1/namespaces/myproject/podsets/example-podset
  UID:                 2705365a-81f7-11e9-9d3c-0800272eeb59
Spec:
  Replicas:  3
Status:
  Pod Names:
    example-podset-podnvlcs
    example-podset-podtvgsf
    example-podset-podzv475
Events:  <none>
gaurav-dalvi commented 5 years ago

Thanks for the analysis. I am using 0.7.0 version of sdk. on that , when I tested on Minikube, it did not work and that why I sent the PR. It worked after my PR. I need to check with newer version of SDK.

Can you check if it works on minishift with 0.7.0 version of SDK.

gaurav-dalvi commented 5 years ago

Without my fix, latest master

kubectl describe  podsets
Name:         example-podset
Namespace:    default
Labels:       <none>
Annotations:  <none>
API Version:  app.example.com/v1alpha1
Kind:         PodSet
Metadata:
  Creation Timestamp:  2019-05-29T17:50:38Z
  Generation:          1
  Resource Version:    1328
  Self Link:           /apis/app.example.com/v1alpha1/namespaces/default/podsets/example-podset
  UID:                 44f7d3ac-823a-11e9-9676-080027c00d04
Spec:
  Replicas:  3
Events:      <none>
bash:master$ operator-sdk version
operator-sdk version: v0.8.1, commit: 33b3bfe10176f8647f5354516fff29dea42b6342
bash:master$ minikube version
minikube version: v1.0.0
bash:master$ kubectl version
Client Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.1", GitCommit:"b7394102d6ef778017f2ca4046abbaa23b88c290", GitTreeState:"clean", BuildDate:"2019-04-08T17:11:31Z", GoVersion:"go1.12.1", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.0", GitCommit:"641856db18352033a0d96dbc99153fa3b27298e5", GitTreeState:"clean", BuildDate:"2019-03-25T15:45:25Z", GoVersion:"go1.12.1", Compiler:"gc", Platform:"linux/amd64"}

With my fix and same other versions:

kubectl create -f deploy/crds/app_v1alpha1_podset_cr.yaml
podset.app.example.com/example-podset created
bash:master$ kubectl describe podset
Name:         example-podset
Namespace:    default
Labels:       <none>
Annotations:  <none>
API Version:  app.example.com/v1alpha1
Kind:         PodSet
Metadata:
  Creation Timestamp:  2019-05-29T17:54:53Z
  Generation:          1
  Resource Version:    1710
  Self Link:           /apis/app.example.com/v1alpha1/namespaces/default/podsets/example-podset
  UID:                 dd0a9e3d-823a-11e9-9676-080027c00d04
Spec:
  Replicas:  3
Status:
  Pod Names:
    example-podset-podjw6rd
    example-podset-podm5t2d
    example-podset-podpmjgt
Events:  <none>
gaurav-dalvi commented 5 years ago

@xcoulon : Can you take a look ?

xcoulon commented 4 years ago

@gaurav-dalvi sorry for this very late response. I worked on the project today and this should be fixed now:

$ oc get podset/example-podset -o yaml
apiVersion: app.example.com/v1alpha1
kind: PodSet
metadata:
  ...
spec:
  replicas: 4
status:
  podNames:
  - example-podset-podd642m
  - example-podset-pod8dv99
  - example-podset-podc5ncx
  - example-podset-podshbh6
  replicas: 4

(note that oc is the equivalent of kubectl for OpenShift)