Conversation
|
Can one of the admins verify this patch? |
|
|
||
| // GenerateKubeConfig returns, if successful, the cluster kubernetes config | ||
| func (c ConfigGenerator) GenerateKubeConfig(workspace string) error { | ||
| //configGenerator := configgenerator.New(c.config) |
| func (c Cluster) runDestroyStep(step string, extraArgs ...string) error { | ||
| if !hasStateFile(c.workspace, step) { | ||
| // there is no statefile, therefore nothing to destroy for this step | ||
| return nil |
There was a problem hiding this comment.
does it make sense to log a warning here? or is this an expected state?
installer/pkg/workflow/cluster.go
Outdated
| } | ||
| return tfApply(c.workspace, step, templateDir, extraArgs...) | ||
|
|
||
| return nil |
installer/pkg/workflow/cluster.go
Outdated
| if err := c.runInstallStep(assetsStep); err != nil { | ||
| return err | ||
| } | ||
| if err := c.generateKubeConfig(); err != nil { |
There was a problem hiding this comment.
just a FYI, I had to move this before the runInstallStep(assetsStep) as part of #3183.
|
Wearing the Ed hat, I'd have to ask which sprint / epic issue does this change tie into? |
There was a problem hiding this comment.
The workspace concept this change introduces is quite foreign to the problem domain that the installer tries to solve - that is, installing Kubernetes (Tectonic / OpenShift) clusters.
Let's try to take a deeper look at it and see how it fits.
Let me pose the following question:
As a user of this tool, I want to install a Tectonic / OpenShift cluster. Previously I could install a cluster without having to supply a workspace as input.
How does supplying a workspace name as an input improve my experience in achieving the goal of installing a cluster?
On the other hand, as a user of this tool, how does not supplying a workspace as an input hinder me from achieving the goal of installing the cluster?
Let's try to answer these questions from the perspective of a user expecting a running cluster after using this tool.
| // returns the directory containing templates for a given step. If platform is | ||
| // specified, it looks for a subdirectory with platform first, falling back if | ||
| // there are no platform-specific templates for that step | ||
| func findStepTemplates(stepName, platform string) (string, error) { |
There was a problem hiding this comment.
One little thing: could you convert platform to lower case? Otherwise I'll have to update that in a separate PR.
There was a problem hiding this comment.
|
As a side note, I'd prefer that major changes like this be discussed briefly as proposals before actually putting any code down. |
| } | ||
|
|
||
| // Install runs, if successful, the steps to install a cluster | ||
| func (c Cluster) Install() error { |
|
hey @alexsomesan on the workspace questions, there's actually no new concept, it's just renaming clusterDir to workspace. In addition (but it's no necessary), I also added it as a flag so the user can use the same source config file to init different clusters |
|
As part of this, it might be nice to abstract Cluster behind an interface; that would help with multi-platform. |
|
@squeed I thought about the interface but wanted to keep as simple as possible for now. Let's add the abstraction if needed with the introduction of the second platform. It also crossed my mind to have a |
b425ddb to
e95f68c
Compare
| var c *workflow.Cluster | ||
| var err error | ||
|
|
||
| newCluster := func(clusterInstallDirFlag string) *workflow.Cluster { |
There was a problem hiding this comment.
can we pull this function definition out of the main func? there is no need to do this inline.
| var c *workflow.Cluster | ||
| var err error | ||
|
|
||
| newCluster := func(clusterInstallDirFlag string) *workflow.Cluster { |
There was a problem hiding this comment.
clusterInstallDirFlag is a funny name for this parameter. the function should not care if it is a flag or an argument or how the string was provided to the function. Could simply be named dir.
| var err error | ||
|
|
||
| newCluster := func(clusterInstallDirFlag string) *workflow.Cluster { | ||
| l, err := log.ParseLevel(*logLevel) |
There was a problem hiding this comment.
creating a cluster should be separate from parsing the log level. In fact, this change introduces a new behavior where log levels are not parsed for the convert command since that command does not execute this newCluster func. I think parsing the log level should be done outside of this func.
| func (c ConfigGenerator) GenerateClusterConfigMaps(workspace string) error { | ||
| clusterGeneratedPath := filepath.Join(workspace, generatedPath) | ||
| if err := os.MkdirAll(clusterGeneratedPath, os.ModeDir|0755); err != nil { | ||
| return fmt.Errorf("Failed to create cluster generated directory at %s", clusterGeneratedPath) |
There was a problem hiding this comment.
We typically make errors lower-case so they can be wrapped.
|
|
||
| kubePath := filepath.Join(workspace, kubeSystemPath) | ||
| if err := os.MkdirAll(kubePath, os.ModeDir|0755); err != nil { | ||
| return fmt.Errorf("Failed to create manifests directory at %s", kubePath) |
|
|
||
| tectonicPath := filepath.Join(workspace, tectonicSystemPath) | ||
| if err := os.MkdirAll(tectonicPath, os.ModeDir|0755); err != nil { | ||
| return fmt.Errorf("Failed to create tectonic directory at %s", tectonicPath) |
| // InitWorkspace generates, if successful, a workspace folder with the config.yaml | ||
| func InitWorkspace(sourceConfigFilePath, workspaceName string) error { | ||
| if sourceConfigFilePath == "" { | ||
| errors.New("no cluster sourceConfigFilePath given for instantiating new cluster") |
There was a problem hiding this comment.
should this be a return? currently this line evaluates the errors.New func but does nothing with the returned value
| errors.New("no cluster sourceConfigFilePath given for instantiating new cluster") | ||
| } | ||
| if workspaceName == "" { | ||
| errors.New("no cluster sourceConfigFilePath given for instantiating new cluster") |
| // It ensures cluster.config and the tfvars file are always up to date with config.yaml | ||
| func NewCluster(workspace string) (*Cluster, error) { | ||
| if workspace == "" { | ||
| errors.New("no workspace dir given for new cluster") |
|
@squat thanks for having a look. Let's close this for now as more internal discussions is needed about the approach before going deeper into the code. cc @alexsomesan |
| // want that to happen atomically with generateTerraformVariables | ||
| func readClusterConfig(workspace string) (*config.Cluster, error) { | ||
| if workspace == "" { | ||
| errors.New("no workspace dir given for reading config") |
There was a problem hiding this comment.
This statement does not do anything with the returned value from errors.New. Did you mean to return here?
|
|
||
| func (c Cluster) runDestroyStep(step string, extraArgs ...string) error { | ||
| if !hasStateFile(c.workspace, step) { | ||
| log.Warningf("there is no statefile, therefore nothing to destroy for the step %s within %s", step, c.workspace) |
There was a problem hiding this comment.
Log lines typically begin with a capital letter
| yamlContent, err := yaml.Marshal(internalCfg) | ||
| internalFileContent := []byte("# Do not touch, auto-generated\n") | ||
| internalFileContent = append(internalFileContent, yamlContent...) | ||
| if err != nil { |
There was a problem hiding this comment.
it's typical to put the error check immediately after the error declaration
The workflow package with the metadata shared by reference across steps has given us high flexibility and ability for making changes and prototype very quickly. As product requirements get clearer and we introduce a second platform we should define clearer boundaries, stronger interfaces and refactor the package.
This proposes a refactor into a more object oriented and hermetic flavour, less prone to side effects. The main logic is in
cluster.go