From 153cb10ceb1b3d77105b7b06d63f8302d9826950 Mon Sep 17 00:00:00 2001 From: Matt Schallert Date: Mon, 3 Jun 2019 14:55:23 -0400 Subject: [PATCH] [api] use status subresource (#152) CRD Status subresource became enabled by default in 1.11. It allows us to only update the status part of a CRD rather than having to update the entire API object, and will unblock OpenAPI validation errors we get if sending the entire CRD. https://v1-12.docs.kubernetes.io/docs/tasks/access-kubernetes-api/custom-resources/custom-resource-definitions/#status-subresource --- pkg/controller/update_cluster.go | 6 ++---- pkg/k8sops/generators.go | 3 +++ pkg/k8sops/generators_test.go | 3 +++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/pkg/controller/update_cluster.go b/pkg/controller/update_cluster.go index 677dbafa..c0dc1980 100644 --- a/pkg/controller/update_cluster.go +++ b/pkg/controller/update_cluster.go @@ -224,10 +224,8 @@ func (c *Controller) setStatusPlacementCreated(cluster *myspec.M3DBCluster) (*my Message: "Created placement", }) - // TODO(schallert): move to UpdateStatus once 1.10 status subresource is out - // of alpha. var err error - cluster, err = c.crdClient.OperatorV1alpha1().M3DBClusters(cluster.Namespace).Update(cluster) + cluster, err = c.crdClient.OperatorV1alpha1().M3DBClusters(cluster.Namespace).UpdateStatus(cluster) if err != nil { err := fmt.Errorf("error updating cluster placement init status: %v", err) c.logger.Error(err.Error()) @@ -269,7 +267,7 @@ func (c *Controller) setStatus(cluster *myspec.M3DBCluster, condition myspec.Clu cond.Message = message cluster.Status.UpdateCondition(cond) - return c.crdClient.OperatorV1alpha1().M3DBClusters(cluster.Namespace).Update(cluster) + return c.crdClient.OperatorV1alpha1().M3DBClusters(cluster.Namespace).UpdateStatus(cluster) } // Updates the cluster if there had been a condition that a pod was diff --git a/pkg/k8sops/generators.go b/pkg/k8sops/generators.go index fde658e9..88ccee11 100644 --- a/pkg/k8sops/generators.go +++ b/pkg/k8sops/generators.go @@ -101,6 +101,9 @@ func (k *k8sops) GenerateCRD() *apiextensionsv1beta1.CustomResourceDefinition { Plural: m3dboperator.ResourcePlural, Kind: m3dboperator.ResourceKind, }, + Subresources: &apiextensionsv1beta1.CustomResourceSubresources{ + Status: &apiextensionsv1beta1.CustomResourceSubresourceStatus{}, + }, }, } } diff --git a/pkg/k8sops/generators_test.go b/pkg/k8sops/generators_test.go index e6904f7e..26f51daa 100644 --- a/pkg/k8sops/generators_test.go +++ b/pkg/k8sops/generators_test.go @@ -59,6 +59,9 @@ func TestGenerateCRD(t *testing.T) { Plural: m3dboperator.ResourcePlural, Kind: m3dboperator.ResourceKind, }, + Subresources: &apiextensionsv1beta1.CustomResourceSubresources{ + Status: &apiextensionsv1beta1.CustomResourceSubresourceStatus{}, + }, }, }