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

Support configuration of default compatibility matrix if matrix is not configured before configuring drivers #118

Merged
merged 7 commits into from
Dec 23, 2021
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
19 changes: 12 additions & 7 deletions vdoctl/cmd/configure_matrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ const (
CompatMatrixConfigMAp = "compat-matrix-config"
LocalFilepath = "Local filepath"
WebURL = "Web URL"
UserConfig = "user"
DefaultNs = "vmware-system-vdo"
)

// matrixConfigureCmd represents the compat command
Expand All @@ -47,8 +49,11 @@ var matrixConfigureCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
ctx := context.Background()

// Check the vdoDeployment Namespace and confirm if VDO operator is running in the env
getVdoNamespace(ctx)
// Confirm if VDO operator is running in the env and get the vdoDeployment Namespace
err, _ := IsVDODeployed(ctx)
if err != nil {
VdoCurrentNamespace = DefaultNs
}

configKey := types.NamespacedName{
Namespace: VdoCurrentNamespace,
Expand All @@ -70,12 +75,12 @@ var matrixConfigureCmd = &cobra.Command{
}
filePath := utils.PromptGetInput(item, errors.New("invalid input"), flag)

err := CreateNamespace(K8sClient, ctx)
err = CreateNamespace(K8sClient, ctx)
if err != nil {
cobra.CheckErr(err)
}

err = CreateConfigMap(filePath, K8sClient, ctx, flag)
err = CreateConfigMap(ctx, filePath, K8sClient, flag, UserConfig)
if err != nil {
cobra.CheckErr(err)
}
Expand All @@ -88,7 +93,7 @@ func init() {
configureCmd.AddCommand(matrixConfigureCmd)
}

func CreateConfigMap(filepath string, client runtimeclient.Client, ctx context.Context, flag utils.ValidationFlags) error {
func CreateConfigMap(ctx context.Context, filepath string, client runtimeclient.Client, flag utils.ValidationFlags, configFlag string) error {

configMapKey := types.NamespacedName{
Namespace: VdoCurrentNamespace,
Expand All @@ -97,13 +102,13 @@ func CreateConfigMap(filepath string, client runtimeclient.Client, ctx context.C
var data map[string]string

if flag == utils.IsURL {
data = map[string]string{"versionConfigURL": filepath, "auto-upgrade": "disabled"}
data = map[string]string{"versionConfigURL": filepath, "auto-upgrade": "disabled", "configured-by": configFlag}
} else {
fileBytes, err := vdoClient.GenerateYamlFromFilePath(filepath)
if err != nil {
cobra.CheckErr(fmt.Sprintf("unable to read the matrix from %s", filepath))
}
data = map[string]string{"versionConfigContent": string(fileBytes), "auto-upgrade": "disabled"}
data = map[string]string{"versionConfigContent": string(fileBytes), "auto-upgrade": "disabled", "configured-by": configFlag}
}

configMapObj := metav1.ObjectMeta{Name: configMapKey.Name, Namespace: configMapKey.Namespace}
Expand Down
9 changes: 6 additions & 3 deletions vdoctl/cmd/delete_vdo.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,19 @@ Currently the command supports vanilla k8s cluster`,
Run: func(cmd *cobra.Command, args []string) {
ctx := context.Background()

// Check the vdoDeployment Namespace and confirm if VDO operator is running in the env
getVdoNamespace(ctx)
// Confirm if VDO operator is running in the env and get the vdoDeployment Namespace
err, _ := IsVDODeployed(ctx)
if err != nil {
cobra.CheckErr(err)
ridaz-zz marked this conversation as resolved.
Show resolved Hide resolved
}

ns := corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: VdoCurrentNamespace,
},
}

err := K8sClient.Delete(ctx, &ns, &client.DeleteOptions{})
err = K8sClient.Delete(ctx, &ns, &client.DeleteOptions{})
if err != nil && !apierrors.IsNotFound(err) {
cobra.CheckErr(fmt.Errorf("Error occurred deleting VDO, %v", err))
}
Expand Down
2 changes: 1 addition & 1 deletion vdoctl/cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Currently the command supports deployment on vanilla k8s cluster`,
cobra.CheckErr(applyErr)
}

fmt.Println("Tip: now that you have deployed VDO, you might want to try 'vdoctl configure drivers' to configure vsphere drivers")
fmt.Println("Tip: now that you have deployed VDO, you might want to try 'vdoctl configure compatibility-matrix' to configure compatibility matrix")
},
}

Expand Down
22 changes: 18 additions & 4 deletions vdoctl/cmd/drivers.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"errors"
"fmt"
"k8s.io/apimachinery/pkg/types"
"os"
"regexp"
"strings"

Expand Down Expand Up @@ -70,9 +71,6 @@ var driversCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
ctx := context.Background()

// Check the vdoDeployment Namespace and confirm if VDO operator is running in the env
getVdoNamespace(ctx)

err, _ := IsVDODeployed(ctx)
if err != nil {
if apierrors.IsNotFound(err) {
Expand All @@ -83,6 +81,22 @@ var driversCmd = &cobra.Command{
}
}

configKey := types.NamespacedName{
Namespace: VdoCurrentNamespace,
Name: CompatMatrixConfigMap,
}
cm := v1.ConfigMap{}

_ = K8sClient.Get(ctx, configKey, &cm)
configFlag := cm.Data["configured-by"]

if !strings.EqualFold(configFlag, UserConfig) {
isConfigRequired := utils.PromptGetInput("VDO is configured with default compatiblity matrix. you can update compatiblity-matrix using 'vdoctl update compatiblity-matrix'. Do you want to use the defaults for compatiblity matrix (Y/N) ? ", errors.New("invalid input"), utils.IsString)
if !strings.EqualFold(isConfigRequired, "Y") {
os.Exit(0)
}
}

var vdoConfigList v1alpha1.VDOConfigList

err = K8sClient.List(ctx, &vdoConfigList)
Expand All @@ -106,7 +120,7 @@ var driversCmd = &cobra.Command{
labels := credentials{
username: "Username",
password: "Password",
vcIp: "VC IP",
vcIp: "VC IP/ FQDN",
topology: v1alpha1.TopologyInfo{
Zone: "Zones",
Region: "Regions",
Expand Down
15 changes: 11 additions & 4 deletions vdoctl/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,25 +159,32 @@ func addKnownTypes(scheme *runtime.Scheme) error {
return nil
}

// getVdoNamespace identifies the namespace in which vdo-operator is deployed
func getVdoNamespace(ctx context.Context) {
func IsVDODeployed(ctx context.Context) (error, *appsv1.Deployment) {
// List Deployments
deploymentList := &appsv1.DeploymentList{}
vdoDeployment := &appsv1.Deployment{}
err := K8sClient.List(ctx, deploymentList)
if err != nil {
cobra.CheckErr(err)
return err, nil
}

//Filter out the deployment using vdo-controller name
for _, deployment := range deploymentList.Items {
if deployment.Name == VdoDeploymentName {
vdoDeployment = &deployment
VdoCurrentNamespace = deployment.Namespace
break
}
}

// If the controller namespace is not identified then it is assumed that vdo is not deployed
if VdoCurrentNamespace == "" {
cobra.CheckErr("VDO is currently not deployed, please deploy using `vdo deploy` command")
return fmt.Errorf("VDO is currently not deployed, please deploy using `vdo deploy` command"), nil
}

if vdoDeployment.Status.Replicas != vdoDeployment.Status.AvailableReplicas {
return fmt.Errorf("not enough replicas of VDO"), nil
}
return err, vdoDeployment

}
16 changes: 1 addition & 15 deletions vdoctl/cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ import (
"fmt"
"github.com/spf13/cobra"
vdov1alpha1 "github.com/vmware-tanzu/vsphere-kubernetes-drivers-operator/api/v1alpha1"
v12 "k8s.io/api/apps/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
)

const VDO_NOT_DEPLOYED = "VDO is not deployed. you can run `vdoctl deploy` command to deploy VDO"
Expand All @@ -39,9 +37,7 @@ var statusCmd = &cobra.Command{

ctx := context.Background()

// Check the vdoDeployment Namespace and confirm if VDO operator is running in the env
getVdoNamespace(ctx)

// Confirm if VDO operator is running in the env and get the vdoDeployment Namespace
err, _ := IsVDODeployed(ctx)
if err != nil {
if apierrors.IsNotFound(err) {
Expand Down Expand Up @@ -90,16 +86,6 @@ var statusCmd = &cobra.Command{
},
}

func IsVDODeployed(ctx context.Context) (error, *v12.Deployment) {
deployment := &v12.Deployment{}
ns := types.NamespacedName{Namespace: VdoCurrentNamespace, Name: VdoDeploymentName}
err := K8sClient.Get(ctx, ns, deployment)
if deployment.Status.Replicas != deployment.Status.AvailableReplicas {
return fmt.Errorf("not enough replicas of VDO"), nil
}
return err, deployment
}

// Fetch VC IP of given VsphereCloudConfig
func fetchVcenterIp(vsphereCloudConfigList vdov1alpha1.VsphereCloudConfigList, configName string) {
for _, vsphereCloudConfig := range vsphereCloudConfigList.Items {
Expand Down
9 changes: 6 additions & 3 deletions vdoctl/cmd/update_matrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,16 @@ func updateMatrix(args []string) {
updatedMatrix := args[0]
ctxNew := context.Background()

// Check the vdoDeployment Namespace and confirm if VDO operator is running in the env
getVdoNamespace(ctxNew)
// Confirm if VDO operator is running in the env and get the vdoDeployment Namespace
err, _ := IsVDODeployed(ctxNew)
if err != nil {
cobra.CheckErr(err)
}

// Check for volumes which have PWX or ROX access mode,
// If any then manual steps are required before updating the driver
volumeAttachmentList := storagev1.VolumeAttachmentList{}
err := K8sClient.List(ctxNew, &volumeAttachmentList)
err = K8sClient.List(ctxNew, &volumeAttachmentList)
if err != nil {
cobra.CheckErr("unable to read the volume list to do pre-check for upgrade")
}
Expand Down
7 changes: 5 additions & 2 deletions vdoctl/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,11 @@ var versionCmd = &cobra.Command{
Logger: ctrllog.Log.WithName("vdoctl:version"),
}

// Check the vdoDeployment Namespace and confirm if VDO operator is running in the env
getVdoNamespace(ctx)
// // Confirm if VDO operator is running in the env and get the vdoDeployment Namespace
err, _ := IsVDODeployed(ctx)
if err != nil {
cobra.CheckErr(err)
}

k8sVersion = getK8sVersion()
err, vdoDeployment := IsVDODeployed(ctx)
Expand Down