Skip to content

Commit 3ff81b3

Browse files
authored
Prepare for release 6.2.4-v8 (#736)
ProductLine: Stash Release: v2021.04.09 Release-tracker: stashed/CHANGELOG#34 Signed-off-by: 1gtm <1gtm@appscode.com>
1 parent 49c75ff commit 3ff81b3

File tree

5 files changed

+117
-34
lines changed

5 files changed

+117
-34
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ require (
1616
kmodules.xyz/client-go v0.0.0-20210218100652-8f345ddfe801
1717
kmodules.xyz/custom-resources v0.0.0-20210222100152-7426e3678989
1818
kmodules.xyz/offshoot-api v0.0.0-20210218144050-e1d794cb382a
19-
stash.appscode.dev/apimachinery v0.11.10
19+
stash.appscode.dev/apimachinery v0.12.2
2020
)
2121

2222
replace bitbucket.org/ww/goautoneg => gomodules.xyz/goautoneg v0.0.0-20120707110453-a547fc61f48d

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,6 @@ sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
895895
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
896896
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
897897
sourcegraph.com/sqs/pbtypes v0.0.0-20180604144634-d3ebe8f20ae4/go.mod h1:ketZ/q3QxT9HOBeFhu6RdvsftgpsbFHBF5Cas6cDKZ0=
898-
stash.appscode.dev/apimachinery v0.11.10 h1:Qeyagj207Xgl3U1YbBTSzdIrY27RK7aunNbDXC6HmPI=
899-
stash.appscode.dev/apimachinery v0.11.10/go.mod h1:/mCvRYT6pzejllri8OMBRHrpYUSD9fMB7GlgZvCRp6Y=
898+
stash.appscode.dev/apimachinery v0.12.2 h1:PYIlO9fBsbai/n/PEcA1u6gdDarDuublPKVYh50vuE8=
899+
stash.appscode.dev/apimachinery v0.12.2/go.mod h1:/mCvRYT6pzejllri8OMBRHrpYUSD9fMB7GlgZvCRp6Y=
900900
vbom.ml/util v0.0.0-20160121211510-db5cfe13f5cc/go.mod h1:so/NYdZXCz+E3ZpW0uAoCj6uzU2+8OWDFv/HxUSs7kI=

vendor/modules.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ kmodules.xyz/prober/api/v1
465465
sigs.k8s.io/structured-merge-diff/v3/value
466466
# sigs.k8s.io/yaml v1.2.0
467467
sigs.k8s.io/yaml
468-
# stash.appscode.dev/apimachinery v0.11.10
468+
# stash.appscode.dev/apimachinery v0.12.2
469469
stash.appscode.dev/apimachinery/apis
470470
stash.appscode.dev/apimachinery/apis/repositories
471471
stash.appscode.dev/apimachinery/apis/repositories/v1alpha1

vendor/stash.appscode.dev/apimachinery/pkg/invoker/restore_invoker.go

Lines changed: 111 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package invoker
1919
import (
2020
"context"
2121
"fmt"
22+
"strings"
2223
"time"
2324

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

2930
core "k8s.io/api/core/v1"
31+
kerr "k8s.io/apimachinery/pkg/api/errors"
3032
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3133
"k8s.io/apimachinery/pkg/types"
3234
"k8s.io/client-go/kubernetes"
3335
"k8s.io/client-go/tools/reference"
3436
kmapi "kmodules.xyz/client-go/api/v1"
3537
core_util "kmodules.xyz/client-go/core/v1"
3638
"kmodules.xyz/client-go/meta"
39+
appcat "kmodules.xyz/custom-resources/apis/appcatalog/v1alpha1"
40+
appcatalog_cs "kmodules.xyz/custom-resources/client/clientset/versioned"
3741
ofst "kmodules.xyz/offshoot-api/api/v1"
3842
)
3943

@@ -59,26 +63,27 @@ type RestoreInvokerStatus struct {
5963
}
6064

6165
type RestoreInvoker struct {
62-
TypeMeta metav1.TypeMeta
63-
ObjectMeta metav1.ObjectMeta
64-
Labels map[string]string
65-
Hash string
66-
Driver v1beta1.Snapshotter
67-
Repository string
68-
TargetsInfo []RestoreTargetInfo
69-
ExecutionOrder v1beta1.ExecutionOrder
70-
Hooks *v1beta1.RestoreHooks
71-
ObjectRef *core.ObjectReference
72-
OwnerRef *metav1.OwnerReference
73-
Status RestoreInvokerStatus
74-
ObjectJson []byte
75-
AddFinalizer func() error
76-
RemoveFinalizer func() error
77-
HasCondition func(*v1beta1.TargetRef, string) (bool, error)
78-
GetCondition func(*v1beta1.TargetRef, string) (int, *kmapi.Condition, error)
79-
SetCondition func(*v1beta1.TargetRef, kmapi.Condition) error
80-
IsConditionTrue func(*v1beta1.TargetRef, string) (bool, error)
81-
NextInOrder func(v1beta1.TargetRef, []v1beta1.RestoreMemberStatus) bool
66+
TypeMeta metav1.TypeMeta
67+
ObjectMeta metav1.ObjectMeta
68+
Labels map[string]string
69+
Hash string
70+
Driver v1beta1.Snapshotter
71+
Repository string
72+
TargetsInfo []RestoreTargetInfo
73+
ExecutionOrder v1beta1.ExecutionOrder
74+
Hooks *v1beta1.RestoreHooks
75+
ObjectRef *core.ObjectReference
76+
OwnerRef *metav1.OwnerReference
77+
Status RestoreInvokerStatus
78+
ObjectJson []byte
79+
AddFinalizer func() error
80+
RemoveFinalizer func() error
81+
HasCondition func(*v1beta1.TargetRef, string) (bool, error)
82+
GetCondition func(*v1beta1.TargetRef, string) (int, *kmapi.Condition, error)
83+
SetCondition func(*v1beta1.TargetRef, kmapi.Condition) error
84+
IsConditionTrue func(*v1beta1.TargetRef, string) (bool, error)
85+
NextInOrder func(v1beta1.TargetRef, []v1beta1.RestoreMemberStatus) bool
86+
EnsureKubeDBIntegration func(appClient appcatalog_cs.Interface) error
8287

8388
UpdateRestoreInvokerStatus func(status RestoreInvokerStatus) (RestoreInvokerStatus, error)
8489
CreateEvent func(eventType, source, reason, message string) error
@@ -253,6 +258,41 @@ func ExtractRestoreInvokerInfo(kubeClient kubernetes.Interface, stashClient cs.I
253258
}, metav1.CreateOptions{})
254259
return err
255260
}
261+
invoker.EnsureKubeDBIntegration = func(appClient appcatalog_cs.Interface) error {
262+
for i := range restoreBatch.Spec.Members {
263+
target := restoreBatch.Spec.Members[i].Target
264+
// Don't do anything if the target is not an AppBinding
265+
if target == nil || !TargetOfGroupKind(target.Ref, appcat.SchemeGroupVersion.Group, appcat.ResourceKindApp) {
266+
continue
267+
}
268+
// Get the respective AppBinding
269+
appBinding, err := appClient.AppcatalogV1alpha1().AppBindings(restoreBatch.Namespace).Get(context.TODO(), target.Ref.Name, metav1.GetOptions{})
270+
if err != nil {
271+
// If the AppBinding does not exist, then don't do anything.
272+
if kerr.IsNotFound(err) {
273+
continue
274+
}
275+
return err
276+
}
277+
// If the AppBinding is not managed by KubeDB, then don't do anything
278+
if manager, err := meta.GetStringValue(appBinding.Labels, meta.ManagedByLabelKey); err != nil || manager != "kubedb.com" {
279+
continue
280+
}
281+
// Extract the name, and managed-by labels. We are not passing "instance" label because there could be multiple AppBindings.
282+
appLabels, err := extractLabels(appBinding.Labels, meta.ManagedByLabelKey, meta.NameLabelKey)
283+
if err != nil {
284+
return err
285+
}
286+
287+
// Add the labels to the invoker
288+
_, _, err = v1beta1_util.PatchRestoreBatch(context.TODO(), stashClient.StashV1beta1(), restoreBatch, func(in *v1beta1.RestoreBatch) *v1beta1.RestoreBatch {
289+
in.Labels = meta.OverwriteKeys(in.Labels, appLabels)
290+
return in
291+
}, metav1.PatchOptions{})
292+
return err
293+
}
294+
return nil
295+
}
256296
case v1beta1.ResourceKindRestoreSession:
257297
// get RestoreSession
258298
restoreSession, err := stashClient.StashV1beta1().RestoreSessions(namespace).Get(context.TODO(), invokerName, metav1.GetOptions{})
@@ -409,6 +449,37 @@ func ExtractRestoreInvokerInfo(kubeClient kubernetes.Interface, stashClient cs.I
409449
}, metav1.CreateOptions{})
410450
return err
411451
}
452+
invoker.EnsureKubeDBIntegration = func(appClient appcatalog_cs.Interface) error {
453+
// Don't do anything if the target is not an AppBinding
454+
if restoreSession.Spec.Target == nil || !TargetOfGroupKind(restoreSession.Spec.Target.Ref, appcat.SchemeGroupVersion.Group, appcat.ResourceKindApp) {
455+
return nil
456+
}
457+
// Get the AppBinding
458+
appBinding, err := appClient.AppcatalogV1alpha1().AppBindings(restoreSession.Namespace).Get(context.TODO(), restoreSession.Spec.Target.Ref.Name, metav1.GetOptions{})
459+
if err != nil {
460+
// If the AppBinding does not exist, then don't do anything.
461+
if kerr.IsNotFound(err) {
462+
return nil
463+
}
464+
return err
465+
}
466+
// If the AppBinding is not managed by KubeDB, then don't do anything
467+
if manager, err := meta.GetStringValue(appBinding.Labels, meta.ManagedByLabelKey); err != nil || manager != "kubedb.com" {
468+
return nil
469+
}
470+
// Extract the name, instance, and managed-by labels.
471+
appLabels, err := extractLabels(appBinding.Labels, meta.InstanceLabelKey, meta.ManagedByLabelKey, meta.NameLabelKey)
472+
if err != nil {
473+
return err
474+
}
475+
476+
// Add the labels to the invoker
477+
_, _, err = v1beta1_util.PatchRestoreSession(context.TODO(), stashClient.StashV1beta1(), restoreSession, func(in *v1beta1.RestoreSession) *v1beta1.RestoreSession {
478+
in.Labels = meta.OverwriteKeys(in.Labels, appLabels)
479+
return in
480+
}, metav1.PatchOptions{})
481+
return err
482+
}
412483
default:
413484
return invoker, fmt.Errorf("failed to extract invoker info. Reason: unknown invoker")
414485
}
@@ -553,3 +624,23 @@ func TargetRestoreCompleted(ref v1beta1.TargetRef, targetStatus []v1beta1.Restor
553624
}
554625
return false
555626
}
627+
628+
func extractLabels(in map[string]string, keys ...string) (map[string]string, error) {
629+
out := make(map[string]string, len(keys))
630+
for _, k := range keys {
631+
val, err := meta.GetStringValue(in, k)
632+
if err != nil {
633+
return nil, err
634+
}
635+
out[k] = val
636+
}
637+
return out, nil
638+
}
639+
640+
func TargetOfGroupKind(targetRef v1beta1.TargetRef, group, kind string) bool {
641+
gv := strings.Split(targetRef.APIVersion, "/")
642+
if len(gv) > 0 && gv[0] == group && targetRef.Kind == kind {
643+
return true
644+
}
645+
return false
646+
}

vendor/stash.appscode.dev/apimachinery/pkg/util/addon.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ package util
1919
import (
2020
"context"
2121
"encoding/json"
22-
"strings"
2322

2423
"stash.appscode.dev/apimachinery/apis/stash/v1beta1"
24+
"stash.appscode.dev/apimachinery/pkg/invoker"
2525

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

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

70-
func targetOfGroupKind(targetRef v1beta1.TargetRef, group, kind string) bool {
71-
gv := strings.Split(targetRef.APIVersion, "/")
72-
if gv[0] == group && targetRef.Kind == kind {
73-
return true
74-
}
75-
return false
76-
}
77-
7870
func getTaskParams(task v1beta1.TaskRef) []appcat.Param {
7971
params := make([]appcat.Param, len(task.Params))
8072
for i := range task.Params {

0 commit comments

Comments
 (0)