Skip to content

Commit

Permalink
Add Update***Status helpers (#465)
Browse files Browse the repository at this point in the history
This is done to support crds with or without spec/status split.
https://github.com/appscode/kutil/pull/151
  • Loading branch information
tamalsaha authored May 4, 2018
1 parent 9a3c0b2 commit 166e928
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 3 deletions.
3 changes: 0 additions & 3 deletions apis/stash/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const (
)

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

Expand Down Expand Up @@ -146,7 +145,6 @@ type RetentionPolicy struct {
}

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

Expand Down Expand Up @@ -218,7 +216,6 @@ const (
)

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

Expand Down

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/stash/v1alpha1/recovery.go

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/stash/v1alpha1/repository.go

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

21 changes: 21 additions & 0 deletions client/clientset/versioned/typed/stash/v1alpha1/util/recovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
cs "github.com/appscode/stash/client/clientset/versioned/typed/stash/v1alpha1"
"github.com/evanphx/json-patch"
"github.com/golang/glog"
"github.com/pkg/errors"
kerr "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -119,3 +120,23 @@ func SetRecoveryStats(c cs.StashV1alpha1Interface, recovery *api.Recovery, path
})
return out, err
}

func UpdateRecoveryStatus(c cs.StashV1alpha1Interface, cur *api.Recovery, transform func(*api.RecoveryStatus) *api.RecoveryStatus, useSubresource ...bool) (*api.Recovery, error) {
if len(useSubresource) > 1 {
return nil, errors.Errorf("invalid value passed for useSubresource: %v", useSubresource)
}

mod := &api.Recovery{
TypeMeta: cur.TypeMeta,
ObjectMeta: cur.ObjectMeta,
Spec: cur.Spec,
Status: *transform(cur.Status.DeepCopy()),
}

if len(useSubresource) == 1 && useSubresource[0] {
return c.Recoveries(cur.Namespace).UpdateStatus(mod)
}

out, _, err := PatchRecoveryObject(c, cur, mod)
return out, err
}
21 changes: 21 additions & 0 deletions client/clientset/versioned/typed/stash/v1alpha1/util/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
cs "github.com/appscode/stash/client/clientset/versioned/typed/stash/v1alpha1"
"github.com/evanphx/json-patch"
"github.com/golang/glog"
"github.com/pkg/errors"
kerr "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -79,3 +80,23 @@ func TryUpdateRepository(c cs.StashV1alpha1Interface, meta metav1.ObjectMeta, tr
}
return
}

func UpdateRepositoryStatus(c cs.StashV1alpha1Interface, cur *api.Repository, transform func(*api.RepositoryStatus) *api.RepositoryStatus, useSubresource ...bool) (*api.Repository, error) {
if len(useSubresource) > 1 {
return nil, errors.Errorf("invalid value passed for useSubresource: %v", useSubresource)
}

mod := &api.Repository{
TypeMeta: cur.TypeMeta,
ObjectMeta: cur.ObjectMeta,
Spec: cur.Spec,
Status: *transform(cur.Status.DeepCopy()),
}

if len(useSubresource) == 1 && useSubresource[0] {
return c.Repositories(cur.Namespace).UpdateStatus(mod)
}

out, _, err := PatchRepositoryObject(c, cur, mod)
return out, err
}

0 comments on commit 166e928

Please sign in to comment.