Skip to content

Commit

Permalink
Prepare for release 9.6.19-v5 (#728)
Browse files Browse the repository at this point in the history
ProductLine: Stash
Release: v2021.03.17
Release-tracker: stashed/CHANGELOG#32
Signed-off-by: 1gtm <[email protected]>
  • Loading branch information
1gtm authored Mar 17, 2021
1 parent 372ed37 commit 7deba42
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 89 deletions.
55 changes: 0 additions & 55 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,9 @@ jobs:
id: qemu
uses: docker/setup-qemu-action@v1

- name: Available platforms
run: echo ${{steps.qemu.outputs.platforms}}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

<<<<<<< HEAD
- name: Prepare Host
run: |
sudo apt-get -qq update || true
sudo apt-get install -y bzr
# install yq
curl -fsSL -o yq https://github.com/mikefarah/yq/releases/download/3.3.0/yq_linux_amd64
chmod +x yq
sudo mv yq /usr/local/bin/yq
# install kubectl
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.17.0/bin/linux/amd64/kubectl
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
=======
>>>>>>> eb1b3a0d... Move docs into stashed/docs repo + Cleanup (#723)
- name: Run checks
run: |
make ci
Expand All @@ -59,39 +40,3 @@ jobs:
run: |
docker login --username ${USERNAME} --password ${DOCKER_TOKEN}
make push
<<<<<<< HEAD

- name: Create Kubernetes cluster
id: kind
uses: engineerd/[email protected]
with:
version: v0.10.0
config: hack/kubernetes/kind.yaml

- name: Prepare cluster for testing
id: local-path
env:
DOCKER_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
USERNAME: 1gtm
REGISTRY_SECRET: regcred
run: |
echo "waiting for nodes to be ready ..."
kubectl wait --for=condition=Ready nodes --all --timeout=5m
kubectl get nodes
echo
echo "install helm 3"
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
echo "install stash-crds chart"
helm repo add appscode https://charts.appscode.com/stable/
helm repo update
helm install stash-crds appscode/stash-crds
helm install kubedb-crds appscode/kubedb-crds
helm install kmodules-crds appscode/kmodules-crds
kubectl wait --for=condition=NamesAccepted crds --all --timeout=5m
- name: Test charts
run: |
export KUBECONFIG=$HOME/.kube/config
make ct
=======
>>>>>>> eb1b3a0d... Move docs into stashed/docs repo + Cleanup (#723)
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
kmodules.xyz/client-go v0.0.0-20210220080427-fd7308e30bb4
kmodules.xyz/custom-resources v0.0.0-20210222235834-b3f8dc56b6a3
kmodules.xyz/offshoot-api v0.0.0-20210220080828-fae1f6c66a89
stash.appscode.dev/apimachinery v0.11.10
stash.appscode.dev/apimachinery v0.12.0
)

replace bitbucket.org/ww/goautoneg => gomodules.xyz/goautoneg v0.0.0-20120707110453-a547fc61f48d
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,6 @@ sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
sourcegraph.com/sqs/pbtypes v0.0.0-20180604144634-d3ebe8f20ae4/go.mod h1:ketZ/q3QxT9HOBeFhu6RdvsftgpsbFHBF5Cas6cDKZ0=
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.0 h1:roRMyPQxcJbAM7mgTzqYrij7GwSuf4AO19EqMTThK9k=
stash.appscode.dev/apimachinery v0.12.0/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
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ kmodules.xyz/prober/api/v1
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.0
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 7deba42

Please sign in to comment.