Skip to content

Commit

Permalink
Prepare for release 4.0.11-v7 (#878)
Browse files Browse the repository at this point in the history
ProductLine: Stash

Release: v2021.04.09

Release-tracker: stashed/CHANGELOG#34
Signed-off-by: 1gtm <1gtm@appscode.com>
  • Loading branch information
1gtm committed Apr 9, 2021
1 parent e734641 commit 7c9f57c
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 34 deletions.
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -19,7 +19,7 @@ require (
kmodules.xyz/custom-resources v0.0.0-20210222100152-7426e3678989
kmodules.xyz/offshoot-api v0.0.0-20210218144050-e1d794cb382a
kubedb.dev/apimachinery v0.14.0-beta.2
stash.appscode.dev/apimachinery v0.11.10
stash.appscode.dev/apimachinery v0.12.2
)

replace bitbucket.org/ww/goautoneg => gomodules.xyz/goautoneg v0.0.0-20120707110453-a547fc61f48d
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Expand Up @@ -1194,6 +1194,6 @@ sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
software.sslmate.com/src/go-pkcs12 v0.0.0-20180114231543-2291e8f0f237/go.mod h1:/xvNRWUqm0+/ZMiF4EX00vrSCMsE4/NHb+Pt3freEeQ=
sourcegraph.com/sqs/pbtypes v0.0.0-20180604144634-d3ebe8f20ae4/go.mod h1:ketZ/q3QxT9HOBeFhu6RdvsftgpsbFHBF5Cas6cDKZ0=
stash.appscode.dev/apimachinery v0.10.0/go.mod h1:TpdBIAiHCtpkUB13SDUyCZ6y+5wmzXBMAf9e72cSPO4=
stash.appscode.dev/apimachinery v0.11.10 h1:Qeyagj207Xgl3U1YbBTSzdIrY27RK7aunNbDXC6HmPI=
stash.appscode.dev/apimachinery v0.11.10/go.mod h1:/mCvRYT6pzejllri8OMBRHrpYUSD9fMB7GlgZvCRp6Y=
stash.appscode.dev/apimachinery v0.12.2 h1:PYIlO9fBsbai/n/PEcA1u6gdDarDuublPKVYh50vuE8=
stash.appscode.dev/apimachinery v0.12.2/go.mod h1:/mCvRYT6pzejllri8OMBRHrpYUSD9fMB7GlgZvCRp6Y=
vbom.ml/util v0.0.0-20160121211510-db5cfe13f5cc/go.mod h1:so/NYdZXCz+E3ZpW0uAoCj6uzU2+8OWDFv/HxUSs7kI=
2 changes: 1 addition & 1 deletion vendor/modules.txt
Expand Up @@ -468,7 +468,7 @@ kubedb.dev/apimachinery/apis/config/v1alpha1
sigs.k8s.io/structured-merge-diff/v3/value
# sigs.k8s.io/yaml v1.2.0
sigs.k8s.io/yaml
# stash.appscode.dev/apimachinery v0.11.10
# stash.appscode.dev/apimachinery v0.12.2
stash.appscode.dev/apimachinery/apis
stash.appscode.dev/apimachinery/apis/repositories
stash.appscode.dev/apimachinery/apis/repositories/v1alpha1
Expand Down
131 changes: 111 additions & 20 deletions vendor/stash.appscode.dev/apimachinery/pkg/invoker/restore_invoker.go
Expand Up @@ -19,6 +19,7 @@ package invoker
import (
"context"
"fmt"
"strings"
"time"

"stash.appscode.dev/apimachinery/apis/stash/v1beta1"
Expand All @@ -27,13 +28,16 @@ import (
v1beta1_util "stash.appscode.dev/apimachinery/client/clientset/versioned/typed/stash/v1beta1/util"

core "k8s.io/api/core/v1"
kerr "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/reference"
kmapi "kmodules.xyz/client-go/api/v1"
core_util "kmodules.xyz/client-go/core/v1"
"kmodules.xyz/client-go/meta"
appcat "kmodules.xyz/custom-resources/apis/appcatalog/v1alpha1"
appcatalog_cs "kmodules.xyz/custom-resources/client/clientset/versioned"
ofst "kmodules.xyz/offshoot-api/api/v1"
)

Expand All @@ -59,26 +63,27 @@ type RestoreInvokerStatus struct {
}

type RestoreInvoker struct {
TypeMeta metav1.TypeMeta
ObjectMeta metav1.ObjectMeta
Labels map[string]string
Hash string
Driver v1beta1.Snapshotter
Repository string
TargetsInfo []RestoreTargetInfo
ExecutionOrder v1beta1.ExecutionOrder
Hooks *v1beta1.RestoreHooks
ObjectRef *core.ObjectReference
OwnerRef *metav1.OwnerReference
Status RestoreInvokerStatus
ObjectJson []byte
AddFinalizer func() error
RemoveFinalizer func() error
HasCondition func(*v1beta1.TargetRef, string) (bool, error)
GetCondition func(*v1beta1.TargetRef, string) (int, *kmapi.Condition, error)
SetCondition func(*v1beta1.TargetRef, kmapi.Condition) error
IsConditionTrue func(*v1beta1.TargetRef, string) (bool, error)
NextInOrder func(v1beta1.TargetRef, []v1beta1.RestoreMemberStatus) bool
TypeMeta metav1.TypeMeta
ObjectMeta metav1.ObjectMeta
Labels map[string]string
Hash string
Driver v1beta1.Snapshotter
Repository string
TargetsInfo []RestoreTargetInfo
ExecutionOrder v1beta1.ExecutionOrder
Hooks *v1beta1.RestoreHooks
ObjectRef *core.ObjectReference
OwnerRef *metav1.OwnerReference
Status RestoreInvokerStatus
ObjectJson []byte
AddFinalizer func() error
RemoveFinalizer func() error
HasCondition func(*v1beta1.TargetRef, string) (bool, error)
GetCondition func(*v1beta1.TargetRef, string) (int, *kmapi.Condition, error)
SetCondition func(*v1beta1.TargetRef, kmapi.Condition) error
IsConditionTrue func(*v1beta1.TargetRef, string) (bool, error)
NextInOrder func(v1beta1.TargetRef, []v1beta1.RestoreMemberStatus) bool
EnsureKubeDBIntegration func(appClient appcatalog_cs.Interface) error

UpdateRestoreInvokerStatus func(status RestoreInvokerStatus) (RestoreInvokerStatus, error)
CreateEvent func(eventType, source, reason, message string) error
Expand Down Expand Up @@ -253,6 +258,41 @@ func ExtractRestoreInvokerInfo(kubeClient kubernetes.Interface, stashClient cs.I
}, metav1.CreateOptions{})
return err
}
invoker.EnsureKubeDBIntegration = func(appClient appcatalog_cs.Interface) error {
for i := range restoreBatch.Spec.Members {
target := restoreBatch.Spec.Members[i].Target
// Don't do anything if the target is not an AppBinding
if target == nil || !TargetOfGroupKind(target.Ref, appcat.SchemeGroupVersion.Group, appcat.ResourceKindApp) {
continue
}
// Get the respective AppBinding
appBinding, err := appClient.AppcatalogV1alpha1().AppBindings(restoreBatch.Namespace).Get(context.TODO(), target.Ref.Name, metav1.GetOptions{})
if err != nil {
// If the AppBinding does not exist, then don't do anything.
if kerr.IsNotFound(err) {
continue
}
return err
}
// If the AppBinding is not managed by KubeDB, then don't do anything
if manager, err := meta.GetStringValue(appBinding.Labels, meta.ManagedByLabelKey); err != nil || manager != "kubedb.com" {
continue
}
// Extract the name, and managed-by labels. We are not passing "instance" label because there could be multiple AppBindings.
appLabels, err := extractLabels(appBinding.Labels, meta.ManagedByLabelKey, meta.NameLabelKey)
if err != nil {
return err
}

// Add the labels to the invoker
_, _, err = v1beta1_util.PatchRestoreBatch(context.TODO(), stashClient.StashV1beta1(), restoreBatch, func(in *v1beta1.RestoreBatch) *v1beta1.RestoreBatch {
in.Labels = meta.OverwriteKeys(in.Labels, appLabels)
return in
}, metav1.PatchOptions{})
return err
}
return nil
}
case v1beta1.ResourceKindRestoreSession:
// get RestoreSession
restoreSession, err := stashClient.StashV1beta1().RestoreSessions(namespace).Get(context.TODO(), invokerName, metav1.GetOptions{})
Expand Down Expand Up @@ -409,6 +449,37 @@ func ExtractRestoreInvokerInfo(kubeClient kubernetes.Interface, stashClient cs.I
}, metav1.CreateOptions{})
return err
}
invoker.EnsureKubeDBIntegration = func(appClient appcatalog_cs.Interface) error {
// Don't do anything if the target is not an AppBinding
if restoreSession.Spec.Target == nil || !TargetOfGroupKind(restoreSession.Spec.Target.Ref, appcat.SchemeGroupVersion.Group, appcat.ResourceKindApp) {
return nil
}
// Get the AppBinding
appBinding, err := appClient.AppcatalogV1alpha1().AppBindings(restoreSession.Namespace).Get(context.TODO(), restoreSession.Spec.Target.Ref.Name, metav1.GetOptions{})
if err != nil {
// If the AppBinding does not exist, then don't do anything.
if kerr.IsNotFound(err) {
return nil
}
return err
}
// If the AppBinding is not managed by KubeDB, then don't do anything
if manager, err := meta.GetStringValue(appBinding.Labels, meta.ManagedByLabelKey); err != nil || manager != "kubedb.com" {
return nil
}
// Extract the name, instance, and managed-by labels.
appLabels, err := extractLabels(appBinding.Labels, meta.InstanceLabelKey, meta.ManagedByLabelKey, meta.NameLabelKey)
if err != nil {
return err
}

// Add the labels to the invoker
_, _, err = v1beta1_util.PatchRestoreSession(context.TODO(), stashClient.StashV1beta1(), restoreSession, func(in *v1beta1.RestoreSession) *v1beta1.RestoreSession {
in.Labels = meta.OverwriteKeys(in.Labels, appLabels)
return in
}, metav1.PatchOptions{})
return err
}
default:
return invoker, fmt.Errorf("failed to extract invoker info. Reason: unknown invoker")
}
Expand Down Expand Up @@ -553,3 +624,23 @@ func TargetRestoreCompleted(ref v1beta1.TargetRef, targetStatus []v1beta1.Restor
}
return false
}

func extractLabels(in map[string]string, keys ...string) (map[string]string, error) {
out := make(map[string]string, len(keys))
for _, k := range keys {
val, err := meta.GetStringValue(in, k)
if err != nil {
return nil, err
}
out[k] = val
}
return out, nil
}

func TargetOfGroupKind(targetRef v1beta1.TargetRef, group, kind string) bool {
gv := strings.Split(targetRef.APIVersion, "/")
if len(gv) > 0 && gv[0] == group && targetRef.Kind == kind {
return true
}
return false
}
12 changes: 2 additions & 10 deletions vendor/stash.appscode.dev/apimachinery/pkg/util/addon.go
Expand Up @@ -19,9 +19,9 @@ package util
import (
"context"
"encoding/json"
"strings"

"stash.appscode.dev/apimachinery/apis/stash/v1beta1"
"stash.appscode.dev/apimachinery/pkg/invoker"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
appcat "kmodules.xyz/custom-resources/apis/appcatalog/v1alpha1"
Expand All @@ -32,7 +32,7 @@ func ExtractAddonInfo(appClient appcatalog_cs.Interface, task v1beta1.TaskRef, t
var params appcat.StashAddon

// If the target is AppBinding and it has addon information set in the parameters section, then extract the addon info.
if targetOfGroupKind(targetRef, appcat.SchemeGroupVersion.Group, appcat.ResourceKindApp) {
if invoker.TargetOfGroupKind(targetRef, appcat.SchemeGroupVersion.Group, appcat.ResourceKindApp) {
// get the AppBinding
appBinding, err := appClient.AppcatalogV1alpha1().AppBindings(namespace).Get(context.TODO(), targetRef.Name, metav1.GetOptions{})
if err != nil {
Expand Down Expand Up @@ -67,14 +67,6 @@ func ExtractAddonInfo(appClient appcatalog_cs.Interface, task v1beta1.TaskRef, t
return &addon, nil
}

func targetOfGroupKind(targetRef v1beta1.TargetRef, group, kind string) bool {
gv := strings.Split(targetRef.APIVersion, "/")
if gv[0] == group && targetRef.Kind == kind {
return true
}
return false
}

func getTaskParams(task v1beta1.TaskRef) []appcat.Param {
params := make([]appcat.Param, len(task.Params))
for i := range task.Params {
Expand Down

0 comments on commit 7c9f57c

Please sign in to comment.