Skip to content

Commit

Permalink
change default deploytype to avoid defaulting to invalid type (#207)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgamero authored May 2, 2023
1 parent 485072e commit 8fffb7e
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 25 deletions.
29 changes: 20 additions & 9 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import (
"os"
"strings"

"golang.org/x/exp/maps"
"gopkg.in/yaml.v3"

"github.com/manifoldco/promptui"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"golang.org/x/exp/maps"
"gopkg.in/yaml.v3"

"github.com/Azure/draft/pkg/config"
"github.com/Azure/draft/pkg/deployments"
Expand All @@ -33,6 +34,10 @@ var flagVariablesMap = make(map[string]string)
const LANGUAGE_VARIABLE = "LANGUAGE"
const TWO_SPACES = " "

// Flag defaults
const emptyDefaultFlagValue = ""
const currentDirDefaultFlagValue = "."

type createCmd struct {
appName string
lang string
Expand Down Expand Up @@ -70,11 +75,11 @@ func newCreateCmd() *cobra.Command {

f := cmd.Flags()

f.StringVarP(&cc.createConfigPath, "create-config", "c", "", "specify the path to the configuration file")
f.StringVarP(&cc.appName, "app", "a", "", "specify the name of the helm release")
f.StringVarP(&cc.lang, "language", "l", "", "specify the language used to create the Kubernetes deployment")
f.StringVarP(&cc.dest, "destination", "d", ".", "specify the path to the project directory")
f.StringVarP(&cc.deployType, "deploy-type", "", ".", "specify deployement type (eg. helm, kustomize, manifests)")
f.StringVarP(&cc.createConfigPath, "create-config", "c", emptyDefaultFlagValue, "specify the path to the configuration file")
f.StringVarP(&cc.appName, "app", "a", emptyDefaultFlagValue, "specify the name of the helm release")
f.StringVarP(&cc.lang, "language", "l", emptyDefaultFlagValue, "specify the language used to create the Kubernetes deployment")
f.StringVarP(&cc.dest, "destination", "d", currentDirDefaultFlagValue, "specify the path to the project directory")
f.StringVarP(&cc.deployType, "deploy-type", "", emptyDefaultFlagValue, "specify deployement type (eg. helm, kustomize, manifests)")
f.BoolVar(&cc.dockerfileOnly, "dockerfile-only", false, "only create Dockerfile in the project directory")
f.BoolVar(&cc.deploymentOnly, "deployment-only", false, "only create deployment files in the project directory")
f.BoolVar(&cc.skipFileDetection, "skip-file-detection", false, "skip file detection step")
Expand Down Expand Up @@ -287,7 +292,10 @@ func (cc *createCmd) createDeployment() error {

if cc.createConfig.DeployType != "" {
deployType = strings.ToLower(cc.createConfig.DeployType)
deployConfig := d.GetConfig(deployType)
deployConfig, err := d.GetConfig(deployType)
if err != nil {
return err
}
if deployConfig == nil {
return errors.New("invalid deployment type")
}
Expand All @@ -311,7 +319,10 @@ func (cc *createCmd) createDeployment() error {
deployType = cc.deployType
}

deployConfig := d.GetConfig(deployType)
deployConfig, err := d.GetConfig(deployType)
if err != nil {
return err
}
customInputs, err = prompts.RunPromptsFromConfigWithSkips(deployConfig, maps.Keys(flagVariablesMap))
if err != nil {
return err
Expand Down
5 changes: 5 additions & 0 deletions cmd/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@ func (mcc *createCmd) mockDetectLanguage() (*config.DraftConfig, string, error)
return nil, "", ErrNoLanguageDetected
}

func TestDefaultValues(t *testing.T) {
assert.Equal(t, emptyDefaultFlagValue, "")
assert.Equal(t, currentDirDefaultFlagValue, ".")
}

func getAllDeploymentFiles(src string) (error, []string) {
deploymentFiles := []string{}
err := filepath.Walk(src,
Expand Down
16 changes: 8 additions & 8 deletions cmd/generate-workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ with draft on AKS. This command assumes the 'setup-gh' command has been run prop
}

f := cmd.Flags()
f.StringVarP(&gwCmd.workflowConfig.AksClusterName, "cluster-name", "c", "", "specify the AKS cluster name")
f.StringVarP(&gwCmd.workflowConfig.AcrName, "registry-name", "r", "", "specify the Azure container registry name")
f.StringVar(&gwCmd.workflowConfig.ContainerName, "container-name", "", "specify the container image name")
f.StringVarP(&gwCmd.workflowConfig.ResourceGroupName, "resource-group", "g", "", "specify the Azure resource group of your AKS cluster")
f.StringVarP(&gwCmd.dest, "destination", "d", ".", "specify the path to the project directory")
f.StringVarP(&gwCmd.workflowConfig.BranchName, "branch", "b", "", "specify the Github branch to automatically deploy from")
f.StringVar(&gwCmd.deployType, "deploy-type", "", "specify the type of deployment")
f.StringVarP(&gwCmd.workflowConfig.AksClusterName, "cluster-name", "c", emptyDefaultFlagValue, "specify the AKS cluster name")
f.StringVarP(&gwCmd.workflowConfig.AcrName, "registry-name", "r", emptyDefaultFlagValue, "specify the Azure container registry name")
f.StringVar(&gwCmd.workflowConfig.ContainerName, "container-name", emptyDefaultFlagValue, "specify the container image name")
f.StringVarP(&gwCmd.workflowConfig.ResourceGroupName, "resource-group", "g", emptyDefaultFlagValue, "specify the Azure resource group of your AKS cluster")
f.StringVarP(&gwCmd.dest, "destination", "d", currentDirDefaultFlagValue, "specify the path to the project directory")
f.StringVarP(&gwCmd.workflowConfig.BranchName, "branch", "b", emptyDefaultFlagValue, "specify the Github branch to automatically deploy from")
f.StringVar(&gwCmd.deployType, "deploy-type", emptyDefaultFlagValue, "specify the type of deployment")
f.StringArrayVarP(&gwCmd.flagVariables, "variable", "", []string{}, "pass additional variables")
f.StringVarP(&gwCmd.workflowConfig.BuildContextPath, "build-context-path", "x", "", "specify the docker build context path")
f.StringVarP(&gwCmd.workflowConfig.BuildContextPath, "build-context-path", "x", emptyDefaultFlagValue, "specify the docker build context path")
gwCmd.templateWriter = &writers.LocalFSWriter{}
return cmd
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/setup-gh.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ application and service principle, and will configure that application to trust
}

f := cmd.Flags()
f.StringVarP(&sc.AppName, "app", "a", "", "specify the Azure Active Directory application name")
f.StringVarP(&sc.SubscriptionID, "subscription-id", "s", "", "specify the Azure subscription ID")
f.StringVarP(&sc.ResourceGroupName, "resource-group", "r", "", "specify the Azure resource group name")
f.StringVarP(&sc.Repo, "gh-repo", "g", "", "specify the github repository link")
f.StringVarP(&sc.AppName, "app", "a", emptyDefaultFlagValue, "specify the Azure Active Directory application name")
f.StringVarP(&sc.SubscriptionID, "subscription-id", "s", emptyDefaultFlagValue, "specify the Azure subscription ID")
f.StringVarP(&sc.ResourceGroupName, "resource-group", "r", emptyDefaultFlagValue, "specify the Azure resource group name")
f.StringVarP(&sc.Repo, "gh-repo", "g", emptyDefaultFlagValue, "specify the github repository link")
sc.Provider = provider
return cmd
}
Expand Down
9 changes: 5 additions & 4 deletions pkg/deployments/deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import (
"io/fs"
"path"

log "github.com/sirupsen/logrus"
"golang.org/x/exp/maps"
"gopkg.in/yaml.v3"

log "github.com/sirupsen/logrus"

"github.com/Azure/draft/pkg/config"
"github.com/Azure/draft/pkg/embedutils"
"github.com/Azure/draft/pkg/osutil"
Expand Down Expand Up @@ -74,12 +75,12 @@ func (d *Deployments) loadConfig(lang string) (*config.DraftConfig, error) {
return &draftConfig, nil
}

func (d *Deployments) GetConfig(deployType string) *config.DraftConfig {
func (d *Deployments) GetConfig(deployType string) (*config.DraftConfig, error) {
val, ok := d.configs[deployType]
if !ok {
return nil
return nil, fmt.Errorf("deployment type: %s is not currently supported", deployType)
}
return val
return val, nil
}

func (d *Deployments) PopulateConfigs() {
Expand Down

0 comments on commit 8fffb7e

Please sign in to comment.