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

ARO-3536: Add error handling when "CLUSTER" env variable is empty. #3007

Merged
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions hack/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ func run(ctx context.Context, log *logrus.Entry) error {
}
clusterName := os.Getenv(Cluster)

if clusterName == "" {
return fmt.Errorf("your environment variable \"CLUSTER\" is empty, please pass a value")
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can use the already defined variable name Cluster instead of hardcoding it on the error message, I would also change a bit the error message, to something like

if clusterName == "" {
    return fmt.Errorf("the environment variable %v is empty, please use a non empty value", Cluster)
}

I also think it would be a good idea to add a similar check in pkg/util/cluster/cluster.go:144 as this funcitonality can be potentially called from other places than the hack script as it is a separate component of a different package.

Something like (pkg/util/cluster/cluster.go:143):

func (c *Cluster) Create(ctx context.Context, vnetResourceGroup, clusterName string, osClusterVersion string) error {
if clusterName == "" {
    return fmt.Errorf("clusterName can not be empty")
}
. . .

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how do you feel like move all validations to one place to ValidateVars(), like:

		if v, found := os.LookupEnv(v); !found || v == "" {
			return fmt.Errorf("environment variable %q unset or set to empty", v)
		}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good idea If we are sure that we are not changing the behavior of the code already using ValidateVars().
😃

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback, I'll take this into consideration and make some updates.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update pushed. I tested the hack script and creation proceeded after doing the update.

osClusterVersion := os.Getenv("OS_CLUSTER_VERSION")

c, err := cluster.New(log, env, os.Getenv("CI") != "")
Expand Down