Skip to content

Commit

Permalink
Add Update***Status helpers
Browse files Browse the repository at this point in the history
This is done to support crds with or without spec/status split.
  • Loading branch information
tamalsaha committed May 4, 2018
1 parent c611f4b commit ce1beb9
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 2 deletions.
1 change: 0 additions & 1 deletion apis/voyager/v1beta1/certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const (
)

// +genclient
// +genclient:skipVerbs=updateStatus
// +k8s:openapi-gen=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

Expand Down
1 change: 0 additions & 1 deletion apis/voyager/v1beta1/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const (
)

// +genclient
// +genclient:skipVerbs=updateStatus
// +k8s:openapi-gen=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

Expand Down
17 changes: 17 additions & 0 deletions client/clientset/versioned/typed/voyager/v1beta1/certificate.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions client/clientset/versioned/typed/voyager/v1beta1/ingress.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,22 @@ func TryUpdateCertificate(c cs.VoyagerV1beta1Interface, meta metav1.ObjectMeta,
}
return
}

func UpateCertificateStatus(c cs.VoyagerV1beta1Interface, cur *api.Certificate, transform func(*api.CertificateStatus) *api.CertificateStatus, useSubresource ...bool) (*api.Certificate, error) {
if len(useSubresource) > 1 {
return nil, errors.Errorf("invalid value passed for useSubresource; %#v", useSubresource)
}

if len(useSubresource) == 1 && useSubresource[0] {
cur.Status = *transform(&cur.Status)
return c.Certificates(cur.Namespace).UpdateStatus(cur)
}

out, _, err := PatchCertificateObject(c, cur, &api.Certificate{
TypeMeta: cur.TypeMeta,
ObjectMeta: cur.ObjectMeta,
Spec: cur.Spec,
Status: *transform(cur.Status.DeepCopy()),
})
return out, err
}
19 changes: 19 additions & 0 deletions client/clientset/versioned/typed/voyager/v1beta1/util/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,22 @@ func TryUpdateIngress(c cs.VoyagerV1beta1Interface, meta metav1.ObjectMeta, tran
}
return
}

func UpdateIngressStatus(c cs.VoyagerV1beta1Interface, cur *api.Ingress, transform func(*api.IngressStatus) *api.IngressStatus, useSubresource ...bool) (*api.Ingress, error) {
if len(useSubresource) > 1 {
return nil, errors.Errorf("invalid value passed for useSubresource; %#v", useSubresource)
}

if len(useSubresource) == 1 && useSubresource[0] {
cur.Status = *transform(&cur.Status)
return c.Ingresses(cur.Namespace).UpdateStatus(cur)
}

out, _, err := PatchIngressObject(c, cur, &api.Ingress{
TypeMeta: cur.TypeMeta,
ObjectMeta: cur.ObjectMeta,
Spec: cur.Spec,
Status: *transform(cur.Status.DeepCopy()),
})
return out, err
}

0 comments on commit ce1beb9

Please sign in to comment.