Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update workload controller for new design #675

Merged
merged 3 commits into from
Mar 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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"
hossainemruz marked this conversation as resolved.
Show resolved Hide resolved
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
)
Loading