Skip to content

Commit

Permalink
WIP: Enhance RestoreCrd to Support OCS CRs Alongside Rook CRs
Browse files Browse the repository at this point in the history
Signed-off-by: Oded Viner <[email protected]>
  • Loading branch information
OdedViner committed Feb 2, 2025
1 parent e16f78b commit 3111818
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cmd/commands/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ var RestoreCmd = &cobra.Command{
verifyOperatorPodIsRunning(cmd.Context(), clientSets)
},
Run: func(cmd *cobra.Command, args []string) {
restore.RestoreCrd(cmd.Context(), clientSets, operatorNamespace, cephClusterNamespace, args)
restore.RestoreCrd(cmd.Context(), clientSets, operatorNamespace, cephClusterNamespace, nil, nil, args)
},
}
6 changes: 4 additions & 2 deletions pkg/crds/crds.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ var CephResources = []string{
}

const (
CephRookIoGroup = "ceph.rook.io"
CephRookResourcesVersion = "v1"
CephRookIoGroup = "ceph.rook.io"
CephRookResourcesVersion = "v1"
OcsOpenshiftIoGroup = "ocs.openshift.io"
OcsOpenshiftResourcesVersion = "v1"
)

const (
Expand Down
14 changes: 12 additions & 2 deletions pkg/restore/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ import (
"k8s.io/apimachinery/pkg/types"
)

func RestoreCrd(ctx context.Context, k8sclientset *k8sutil.Clientsets, operatorNamespace, clusterNamespace string, args []string) {
func RestoreCrd(ctx context.Context, k8sclientset *k8sutil.Clientsets, operatorNamespace, clusterNamespace string,
groupNameOptional, versionResourceOptional *string, args []string) {
crd := args[0]

var crName string
Expand All @@ -42,7 +43,16 @@ func RestoreCrd(ctx context.Context, k8sclientset *k8sutil.Clientsets, operatorN
}

logging.Info("Detecting which resources to restore for crd %q", crd)
crdList, err := k8sclientset.ListResourcesDynamically(ctx, crds.CephRookIoGroup, crds.CephRookResourcesVersion, crd, clusterNamespace)
var groupName, versionResource string
// Set default values for groupName and versionResource
if groupNameOptional == nil || versionResourceOptional == nil {
groupName = crds.CephRookIoGroup
versionResource = crds.CephRookResourcesVersion
} else {
groupName = *groupNameOptional
versionResource = *versionResourceOptional
}
crdList, err := k8sclientset.ListResourcesDynamically(ctx, groupName, versionResource, crd, clusterNamespace)
if err != nil {
logging.Fatal(fmt.Errorf("Failed to list resources for crd %v", err))
}
Expand Down

0 comments on commit 3111818

Please sign in to comment.