-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat: allow know the project type by the config file #3330
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -207,11 +207,32 @@ func GetOperatorType() OperatorType { | |
| return OperatorTypeUnknown | ||
| } | ||
|
|
||
| // PluginKeyToOperatorType converts a plugin key string to an operator project | ||
| // type. | ||
| // TODO(estroz): this can probably be made more robust by checking known | ||
|
asmacdo marked this conversation as resolved.
|
||
| // plugin keys directly. | ||
| func PluginKeyToOperatorType(pluginKey string) OperatorType { | ||
| switch { | ||
| case strings.HasPrefix(pluginKey, "go"): | ||
| return OperatorTypeGo | ||
| case strings.HasPrefix(pluginKey, "helm"): | ||
| return OperatorTypeHelm | ||
| case strings.HasPrefix(pluginKey, "ansible"): | ||
| return OperatorTypeAnsible | ||
| } | ||
| return OperatorTypeUnknown | ||
| } | ||
|
|
||
| // IsOperatorGo returns true when the layout field in PROJECT file has the Go prefix key. | ||
| // NOTE: For the legacy, returns true when the project contains the cmd/manager directory and main.go file. | ||
| func IsOperatorGo() bool { | ||
| // todo: in the future we should check the plugin prefix to ensure the operator type | ||
| // for now, we can assume that any project with the kubebuilder layout is Go Type | ||
| // If the project has the new layout we will check the type in the config file | ||
| if kbutil.HasProjectFile() { | ||
| return true | ||
| cfg, err := kbutil.ReadConfig() | ||
| if err != nil { | ||
| log.Fatalf("Error reading config: %v", err) | ||
| } | ||
| return cfg.IsV2() || PluginKeyToOperatorType(cfg.Layout) == OperatorTypeGo | ||
| } | ||
|
|
||
| // todo: remove the following code when the legacy layout is no longer supported | ||
|
|
@@ -225,7 +246,18 @@ func IsOperatorGo() bool { | |
| return err == nil || os.IsExist(err) | ||
| } | ||
|
|
||
| // IsOperatorAnsible returns true when the layout field in PROJECT file has the Ansible prefix key. | ||
| // NOTE: For the legacy, returns true when the project contains the roles and the molecule directory. | ||
| func IsOperatorAnsible() bool { | ||
|
camilamacedo86 marked this conversation as resolved.
|
||
| // If the project is in the new layout, check the config file's plugin type. | ||
| if kbutil.HasProjectFile() { | ||
|
camilamacedo86 marked this conversation as resolved.
|
||
| cfg, err := kbutil.ReadConfig() | ||
| if err != nil { | ||
| log.Fatalf("Error reading config: %v", err) | ||
| } | ||
| return PluginKeyToOperatorType(cfg.Layout) == OperatorTypeAnsible | ||
| } | ||
| // todo(camilamacedo86): remove when the legacy layout is no longer supported | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will the roles dir no longer be in the new layout?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The roles dir will be in the new layout, however, see:
|
||
| stat, err := os.Stat(rolesDir) | ||
| if (err == nil && stat.IsDir()) || os.IsExist(err) { | ||
| return true | ||
|
|
@@ -238,7 +270,18 @@ func IsOperatorAnsible() bool { | |
| return err == nil || os.IsExist(err) | ||
| } | ||
|
|
||
| // IsOperatorHelm returns true when the layout field in PROJECT file has the Helm prefix key. | ||
| // NOTE: For the legacy, returns true when the project contains the helm-charts directory. | ||
| func IsOperatorHelm() bool { | ||
| // If the project has the new layout we will check the type in the config file | ||
| if kbutil.HasProjectFile() { | ||
| cfg, err := kbutil.ReadConfig() | ||
| if err != nil { | ||
| log.Fatalf("Error reading config: %v", err) | ||
| } | ||
| return PluginKeyToOperatorType(cfg.Layout) == OperatorTypeHelm | ||
| } | ||
| // todo(camilamacedo86): remove when the legacy layout is no longer supported | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will the charts dir no longer be in the new layout?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto above. We can scaffold a project without any api. |
||
| stat, err := os.Stat(helmChartsDir) | ||
| return (err == nil && stat.IsDir()) || os.IsExist(err) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move the implementation to the project util since is required/useful to check the project type.