Skip to content

Commit

Permalink
Update workload controller for new design (#675)
Browse files Browse the repository at this point in the history
**Requirements:**
- [x] Merge #647 to master
- [x] Merge #673 to master
- [x] Merge #674 to master
- [x] Merge #671 to master
- [x] Rebase against master

**Tasks:**
- [x] Update Restore Logic
- [x] Update Backup Logic
- [x] Update Workload Controllers
	- [x] Deployment
	- [x] DaemonSet
	- [x] ReplicationControler
	- [x] ReplicaSet
	- [x] StatefulSet
- [x] Fix ConfigMap lock deletion and RBAC stuff deletion logic
- [x] Ensure sidecar/init-container according to new design
	- [x] Ensure Restore init-container injection
	- [x] Ensure Restore init-container deletion
	- [x] Ensure Backup sidecar injection
	- [x] Ensure Backup sidecar deletion
- [x] Add new backup command (sagor is working)
- [x] Add new restore command

- [x] Add controller (possibly in different PR)
	- [x] PersistentVolumeClaim
	- [x] AppBinding
  • Loading branch information
hossainemruz authored and tamalsaha committed Mar 21, 2019
1 parent 13fb68b commit 83f1c6e
Show file tree
Hide file tree
Showing 148 changed files with 28,419 additions and 6,223 deletions.
1,340 changes: 1,335 additions & 5 deletions api/crds/v1beta1/backupconfiguration.yaml

Large diffs are not rendered by default.

1,303 changes: 1,302 additions & 1 deletion api/crds/v1beta1/backupconfigurationtemplate.yaml

Large diffs are not rendered by default.

453 changes: 452 additions & 1 deletion api/crds/v1beta1/function.yaml

Large diffs are not rendered by default.

1,357 changes: 1,346 additions & 11 deletions api/crds/v1beta1/restoresession.yaml

Large diffs are not rendered by default.

5,965 changes: 1,454 additions & 4,511 deletions api/openapi-spec/swagger.json

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion apis/constants.go
Expand Up @@ -15,8 +15,11 @@ const (
Hostname = "HOSTNAME"

TargetName = "TARGET_NAME"
TargetDirectories = "TARGET_DIRECTORIES"
TargetAPIVersion = "TARGET_API_VERSION"
TargetKind = "TARGET_KIND"
TargetNamespace = "TARGET_NAMESPACE"
TargetMountPath = "TARGET_MOUNT_PATH"
TargetDirectories = "TARGET_DIRECTORIES"

RestoreDirectories = "RESTORE_DIRECTORIES"
RestoreSnapshots = "RESTORE_SNAPSHOTS"
Expand Down
581 changes: 581 additions & 0 deletions apis/repositories/v1alpha1/openapi_generated.go

Large diffs are not rendered by default.

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

This file was deleted.

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

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions apis/stash/v1alpha1/restic_helpers.go
@@ -1,11 +1,21 @@
package v1alpha1

import (
"hash/fnv"
"strconv"

"github.com/appscode/stash/apis"
apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
hashutil "k8s.io/kubernetes/pkg/util/hash"
crdutils "kmodules.xyz/client-go/apiextensions/v1beta1"
)

func (r Restic) GetSpecHash() string {
hash := fnv.New64a()
hashutil.DeepHashObject(hash, r.Spec)
return strconv.FormatUint(hash.Sum64(), 10)
}

func (c Restic) CustomResourceDefinition() *apiextensions.CustomResourceDefinition {
return crdutils.NewCustomResourceDefinition(crdutils.Config{
Group: SchemeGroupVersion.Group,
Expand Down
34 changes: 14 additions & 20 deletions apis/stash/v1alpha1/workload.go
Expand Up @@ -3,14 +3,8 @@ package v1alpha1
import (
"fmt"
"strings"
)

const (
KindDeployment = "Deployment"
KindReplicaSet = "ReplicaSet"
KindReplicationController = "ReplicationController"
KindStatefulSet = "StatefulSet"
KindDaemonSet = "DaemonSet"
"github.com/appscode/stash/apis"
)

// LocalTypedReference contains enough information to let you inspect or modify the referred object.
Expand All @@ -34,15 +28,15 @@ func (workload *LocalTypedReference) Canonicalize() error {
}
switch strings.ToLower(workload.Kind) {
case "deployments", "deployment", "deploy":
workload.Kind = KindDeployment
workload.Kind = apis.KindDeployment
case "replicasets", "replicaset", "rs":
workload.Kind = KindReplicaSet
workload.Kind = apis.KindReplicaSet
case "replicationcontrollers", "replicationcontroller", "rc":
workload.Kind = KindReplicationController
workload.Kind = apis.KindReplicationController
case "statefulsets", "statefulset":
workload.Kind = KindStatefulSet
workload.Kind = apis.KindStatefulSet
case "daemonsets", "daemonset", "ds":
workload.Kind = KindDaemonSet
workload.Kind = apis.KindDaemonSet
default:
return fmt.Errorf(`unrecognized workload "Kind" %v`, workload.Kind)
}
Expand All @@ -52,11 +46,11 @@ func (workload *LocalTypedReference) Canonicalize() error {
func (workload LocalTypedReference) GetRepositoryCRDName(podName, nodeName string) string {
name := ""
switch workload.Kind {
case KindDeployment, KindReplicaSet, KindReplicationController:
case apis.KindDeployment, apis.KindReplicaSet, apis.KindReplicationController:
name = strings.ToLower(workload.Kind) + "." + workload.Name
case KindStatefulSet:
case apis.KindStatefulSet:
name = strings.ToLower(workload.Kind) + "." + podName
case KindDaemonSet:
case apis.KindDaemonSet:
name = strings.ToLower(workload.Kind) + "." + workload.Name + "." + nodeName
}
return name
Expand All @@ -71,16 +65,16 @@ func (workload LocalTypedReference) HostnamePrefix(podName, nodeName string) (ho
return "", "", fmt.Errorf("missing workload name or kind")
}
switch workload.Kind {
case KindDeployment, KindReplicaSet, KindReplicationController:
case apis.KindDeployment, apis.KindReplicaSet, apis.KindReplicationController:
return workload.Name, strings.ToLower(workload.Kind) + "/" + workload.Name, nil
case KindStatefulSet:
case apis.KindStatefulSet:
if podName == "" {
return "", "", fmt.Errorf("missing podName for %s", KindStatefulSet)
return "", "", fmt.Errorf("missing podName for %s", apis.KindStatefulSet)
}
return podName, strings.ToLower(workload.Kind) + "/" + podName, nil
case KindDaemonSet:
case apis.KindDaemonSet:
if nodeName == "" {
return "", "", fmt.Errorf("missing nodeName for %s", KindDaemonSet)
return "", "", fmt.Errorf("missing nodeName for %s", apis.KindDaemonSet)
}
return nodeName, strings.ToLower(workload.Kind) + "/" + workload.Name + "/" + nodeName, nil
default:
Expand Down
23 changes: 18 additions & 5 deletions apis/stash/v1beta1/annotations.go
@@ -1,10 +1,23 @@
package v1beta1

const (
BackupKey = "backup.appscode.com"
LastAppliedConfiguration = BackupKey + "/last-applied-configuration"
VersionTag = BackupKey + "/tag"
VersionTag = BackupKey + "/tag"
// ResourceVersion will be used to trigger restarts for ReplicaSet and RC pods
ResourceHash = BackupKey + "/resource-hash"
StashKey = "stash.appscode.com"
StashKey = "stash.appscode.com"
BackupKey = "backup.appscode.com"
RestoreKey = "restore.appscode.com"
SuffixLastAppliedConfiguration = "/last-applied-configuration"
SuffixResourceHash = "/resource-hash"

KeyBackupConfigurationTemplate = StashKey + "/backup-template"
KeyTargetDirectories = StashKey + "/target-directories"
KeyMountPath = StashKey + "/mountpath"
KeyVolumeMounts = StashKey + "/volume-mounts"

KeyLastAppliedRestoreSession = RestoreKey + SuffixLastAppliedConfiguration
KeyLastAppliedBackupConfiguration = BackupKey + SuffixLastAppliedConfiguration

AppliedBackupConfigurationSpecHash = BackupKey + SuffixResourceHash
AppliedRestoreSessionSpecHash = RestoreKey + SuffixResourceHash
ResourceHash = BackupKey + SuffixResourceHash
)

0 comments on commit 83f1c6e

Please sign in to comment.