Skip to content

Commit

Permalink
Various fixes (#67)
Browse files Browse the repository at this point in the history
- Replace appscode/go with gomodules.xyz/x
- Pass uid to UpdateStatus transform function
- Move apis/invoker to pkg/invoker
- Rename Invoker/TargetInfo to BackupInvoker/BackupTargetInfo
- Ignore status update when uid does not match

Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha authored Nov 5, 2020
1 parent 45f4ed3 commit c2190f6
Show file tree
Hide file tree
Showing 69 changed files with 1,439 additions and 1,976 deletions.
2 changes: 0 additions & 2 deletions .config/api-rules/violation_exceptions.list
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,6 @@ API rule violation: list_type_missing,stash.appscode.dev/apimachinery/apis/stash
API rule violation: list_type_missing,stash.appscode.dev/apimachinery/apis/stash/v1beta1,TaskRef,Params
API rule violation: list_type_missing,stash.appscode.dev/apimachinery/apis/stash/v1beta1,TaskSpec,Steps
API rule violation: list_type_missing,stash.appscode.dev/apimachinery/apis/stash/v1beta1,TaskSpec,Volumes
API rule violation: names_match,github.com/appscode/go/encoding/json/types,IntHash,generation
API rule violation: names_match,github.com/appscode/go/encoding/json/types,IntHash,hash
API rule violation: names_match,k8s.io/api/core/v1,AzureDiskVolumeSource,DataDiskURI
API rule violation: names_match,k8s.io/api/core/v1,ContainerStatus,LastTerminationState
API rule violation: names_match,k8s.io/api/core/v1,DaemonEndpoint,Port
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ openapi-%:
openapi-gen \
--v 1 --logtostderr \
--go-header-file "./hack/license/go.txt" \
--input-dirs "$(GO_PKG)/$(REPO)/apis/$(subst _,/,$*),k8s.io/apimachinery/pkg/apis/meta/v1,k8s.io/apimachinery/pkg/api/resource,k8s.io/apimachinery/pkg/runtime,k8s.io/apimachinery/pkg/util/intstr,k8s.io/apimachinery/pkg/version,k8s.io/api/core/v1,k8s.io/api/apps/v1,kmodules.xyz/offshoot-api/api/v1,github.com/appscode/go/encoding/json/types,kmodules.xyz/custom-resources/apis/appcatalog/v1alpha1,k8s.io/api/rbac/v1,kmodules.xyz/objectstore-api/api/v1,kmodules.xyz/prober/api/v1,kmodules.xyz/client-go/api/v1" \
--input-dirs "$(GO_PKG)/$(REPO)/apis/$(subst _,/,$*),k8s.io/apimachinery/pkg/apis/meta/v1,k8s.io/apimachinery/pkg/api/resource,k8s.io/apimachinery/pkg/runtime,k8s.io/apimachinery/pkg/util/intstr,k8s.io/apimachinery/pkg/version,k8s.io/api/core/v1,k8s.io/api/apps/v1,kmodules.xyz/offshoot-api/api/v1,kmodules.xyz/custom-resources/apis/appcatalog/v1alpha1,k8s.io/api/rbac/v1,kmodules.xyz/objectstore-api/api/v1,kmodules.xyz/prober/api/v1,kmodules.xyz/client-go/api/v1" \
--output-package "$(GO_PKG)/$(REPO)/apis/$(subst _,/,$*)" \
--report-filename .config/api-rules/violation_exceptions.list

Expand Down
14 changes: 0 additions & 14 deletions apis/repositories/v1alpha1/openapi_generated.go

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

14 changes: 0 additions & 14 deletions apis/stash/v1alpha1/openapi_generated.go

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

14 changes: 0 additions & 14 deletions apis/stash/v1beta1/openapi_generated.go

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

26 changes: 0 additions & 26 deletions client/clientset/versioned/typed/stash/v1alpha1/util/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,7 @@ limitations under the License.
package util

import (
"fmt"
"reflect"

api "stash.appscode.dev/apimachinery/apis/stash/v1alpha1"

jsoniter "github.com/json-iterator/go"
"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/runtime/schema"
"kmodules.xyz/client-go/meta"
)

var json = jsoniter.ConfigFastest

func GetGroupVersionKind(v interface{}) schema.GroupVersionKind {
return api.SchemeGroupVersion.WithKind(meta.GetKind(v))
}

func AssignTypeKind(v interface{}) error {
if reflect.ValueOf(v).Kind() != reflect.Ptr {
return fmt.Errorf("%v must be a pointer", v)
}

switch u := v.(type) {
case *api.Restic:
u.APIVersion = api.SchemeGroupVersion.String()
u.Kind = meta.GetKind(v)
return nil
}
return errors.New("unknown api object type")
}
13 changes: 9 additions & 4 deletions client/clientset/versioned/typed/stash/v1alpha1/util/recovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,20 @@ func UpdateRecoveryStatus(
ctx context.Context,
c cs.StashV1alpha1Interface,
meta metav1.ObjectMeta,
transform func(*api.RecoveryStatus) *api.RecoveryStatus,
transform func(*api.RecoveryStatus) (types.UID, *api.RecoveryStatus),
opts metav1.UpdateOptions,
) (result *api.Recovery, err error) {
apply := func(x *api.Recovery) *api.Recovery {
uid, updatedStatus := transform(x.Status.DeepCopy())
// Ignore status update when uid does not match
if uid != "" && uid != x.UID {
return x
}
out := &api.Recovery{
TypeMeta: x.TypeMeta,
ObjectMeta: x.ObjectMeta,
Spec: x.Spec,
Status: *transform(x.Status.DeepCopy()),
Status: *updatedStatus,
}
return out
}
Expand Down Expand Up @@ -152,7 +157,7 @@ func UpdateRecoveryStatus(
}

func SetRecoveryStats(ctx context.Context, c cs.StashV1alpha1Interface, recovery metav1.ObjectMeta, path string, d time.Duration, phase api.RecoveryPhase, opts metav1.UpdateOptions) (*api.Recovery, error) {
return UpdateRecoveryStatus(ctx, c, recovery, func(in *api.RecoveryStatus) *api.RecoveryStatus {
return UpdateRecoveryStatus(ctx, c, recovery, func(in *api.RecoveryStatus) (types.UID, *api.RecoveryStatus) {
found := false
for _, stats := range in.Stats {
if stats.Path == path {
Expand All @@ -168,6 +173,6 @@ func SetRecoveryStats(ctx context.Context, c cs.StashV1alpha1Interface, recovery
Phase: phase,
})
}
return in
return "", in
}, opts)
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,20 @@ func UpdateRepositoryStatus(
ctx context.Context,
c cs.StashV1alpha1Interface,
meta metav1.ObjectMeta,
transform func(*api.RepositoryStatus) *api.RepositoryStatus,
transform func(*api.RepositoryStatus) (types.UID, *api.RepositoryStatus),
opts metav1.UpdateOptions,
) (result *api.Repository, err error) {
apply := func(x *api.Repository) *api.Repository {
uid, updatedStatus := transform(x.Status.DeepCopy())
// Ignore status update when uid does not match
if uid != "" && uid != x.UID {
return x
}
out := &api.Repository{
TypeMeta: x.TypeMeta,
ObjectMeta: x.ObjectMeta,
Spec: x.Spec,
Status: *transform(x.Status.DeepCopy()),
Status: *updatedStatus,
}
return out
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,20 @@ func UpdateBackupBatchStatus(
ctx context.Context,
c cs.StashV1beta1Interface,
meta metav1.ObjectMeta,
transform func(*api.BackupBatchStatus) *api.BackupBatchStatus,
transform func(*api.BackupBatchStatus) (types.UID, *api.BackupBatchStatus),
opts metav1.UpdateOptions,
) (result *api.BackupBatch, err error) {
apply := func(x *api.BackupBatch) *api.BackupBatch {
uid, updatedStatus := transform(x.Status.DeepCopy())
// Ignore status update when uid does not match
if uid != "" && uid != x.UID {
return x
}
out := &api.BackupBatch{
TypeMeta: x.TypeMeta,
ObjectMeta: x.ObjectMeta,
Spec: x.Spec,
Status: *transform(x.Status.DeepCopy()),
Status: *updatedStatus,
}
return out
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,20 @@ func UpdateBackupConfigurationStatus(
ctx context.Context,
c cs.StashV1beta1Interface,
meta metav1.ObjectMeta,
transform func(*api.BackupConfigurationStatus) *api.BackupConfigurationStatus,
transform func(*api.BackupConfigurationStatus) (types.UID, *api.BackupConfigurationStatus),
opts metav1.UpdateOptions,
) (result *api.BackupConfiguration, err error) {
apply := func(x *api.BackupConfiguration) *api.BackupConfiguration {
uid, updatedStatus := transform(x.Status.DeepCopy())
// Ignore status update when uid does not match
if uid != "" && uid != x.UID {
return x
}
out := &api.BackupConfiguration{
TypeMeta: x.TypeMeta,
ObjectMeta: x.ObjectMeta,
Spec: x.Spec,
Status: *transform(x.Status.DeepCopy()),
Status: *updatedStatus,
}
return out
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,20 @@ func UpdateBackupSessionStatus(
ctx context.Context,
c cs.StashV1beta1Interface,
meta metav1.ObjectMeta,
transform func(*api_v1beta1.BackupSessionStatus) *api_v1beta1.BackupSessionStatus,
transform func(*api_v1beta1.BackupSessionStatus) (types.UID, *api_v1beta1.BackupSessionStatus),
opts metav1.UpdateOptions,
) (result *api_v1beta1.BackupSession, err error) {
apply := func(x *api_v1beta1.BackupSession) *api_v1beta1.BackupSession {
uid, updatedStatus := transform(x.Status.DeepCopy())
// Ignore status update when uid does not match
if uid != "" && uid != x.UID {
return x
}
out := &api_v1beta1.BackupSession{
TypeMeta: x.TypeMeta,
ObjectMeta: x.ObjectMeta,
Spec: x.Spec,
Status: *transform(x.Status.DeepCopy()),
Status: *updatedStatus,
}
return out
}
Expand Down Expand Up @@ -158,10 +163,9 @@ func UpdateBackupSessionStatusForHost(
hostStats api_v1beta1.HostBackupStats,
opts metav1.UpdateOptions,
) (*api_v1beta1.BackupSession, error) {

return UpdateBackupSessionStatus(ctx, c, backupSession, func(in *api_v1beta1.BackupSessionStatus) *api_v1beta1.BackupSessionStatus {
return UpdateBackupSessionStatus(ctx, c, backupSession, func(in *api_v1beta1.BackupSessionStatus) (types.UID, *api_v1beta1.BackupSessionStatus) {
in.Targets = UpsertHostForTarget(in.Targets, targetRef, hostStats)
return in
return "", in
}, opts)
}

Expand Down
26 changes: 0 additions & 26 deletions client/clientset/versioned/typed/stash/v1beta1/util/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,7 @@ limitations under the License.
package util

import (
"fmt"
"reflect"

api "stash.appscode.dev/apimachinery/apis/stash/v1alpha1"

jsoniter "github.com/json-iterator/go"
"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/runtime/schema"
"kmodules.xyz/client-go/meta"
)

var json = jsoniter.ConfigFastest

func GetGroupVersionKind(v interface{}) schema.GroupVersionKind {
return api.SchemeGroupVersion.WithKind(meta.GetKind(v))
}

func AssignTypeKind(v interface{}) error {
if reflect.ValueOf(v).Kind() != reflect.Ptr {
return fmt.Errorf("%v must be a pointer", v)
}

switch u := v.(type) {
case *api.Restic:
u.APIVersion = api.SchemeGroupVersion.String()
u.Kind = meta.GetKind(v)
return nil
}
return errors.New("unknown api object type")
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,20 @@ func UpdateRestoreBatchStatus(
ctx context.Context,
c cs.StashV1beta1Interface,
meta metav1.ObjectMeta,
transform func(*api.RestoreBatchStatus) *api.RestoreBatchStatus,
transform func(*api.RestoreBatchStatus) (types.UID, *api.RestoreBatchStatus),
opts metav1.UpdateOptions,
) (result *api.RestoreBatch, err error) {
apply := func(x *api.RestoreBatch) *api.RestoreBatch {
uid, updatedStatus := transform(x.Status.DeepCopy())
// Ignore status update when uid does not match
if uid != "" && uid != x.UID {
return x
}
out := &api.RestoreBatch{
TypeMeta: x.TypeMeta,
ObjectMeta: x.ObjectMeta,
Spec: x.Spec,
Status: *transform(x.Status.DeepCopy()),
Status: *updatedStatus,
}
return out
}
Expand Down
Loading

0 comments on commit c2190f6

Please sign in to comment.