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 K8sApp by pipectl init in simplest way #4759

Merged
merged 6 commits into from
Feb 24, 2024
Merged

Conversation

t-kikuc
Copy link
Member

@t-kikuc t-kikuc commented Jan 26, 2024

What this PR does / why we need it:

Support generating the simplest app.pipecd.yaml for K8sApp by pipectl init
, selecting Kustomize or Helm.

Which issue(s) this PR fixes:

Fixes #4753

Does this PR introduce a user-facing change?: no

  • How are users affected by this change:
  • Is this breaking change:
  • How to migrate (if breaking change):

Copy link

codecov bot commented Jan 26, 2024

Codecov Report

Attention: 24 lines in your changes are missing coverage. Please review.

Comparison is base (7b26b02) 31.02% compared to head (a0e9045) 31.39%.
Report is 16 commits behind head on master.

Files Patch % Lines
pkg/app/pipectl/cmd/initialize/kubernetes.go 86.30% 16 Missing and 7 partials ⚠️
pkg/app/pipectl/cmd/initialize/initialize.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4759      +/-   ##
==========================================
+ Coverage   31.02%   31.39%   +0.37%     
==========================================
  Files         225      226       +1     
  Lines       26257    26521     +264     
==========================================
+ Hits         8146     8327     +181     
- Misses      17460    17534      +74     
- Partials      651      660       +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@t-kikuc
Copy link
Member Author

t-kikuc commented Jan 26, 2024

/review

Copy link
Contributor

PR Analysis

Main theme

Enhancement

PR summary

This PR adds functionality to generate configuration for Kubernetes-based applications in the PipeCD project initialization command (pipectl init). Specifically, it allows the user to choose whether their application will manage its manifests using Kustomize or Helm and then prompts the user to enter the details needed for the chosen method, including support for a remote Helm chart or a local chart.

Type of PR

Enhancement

PR Feedback:

General suggestions

The implementation of Kubernetes configuration generation seems to cover both Helm and Kustomize users, which is comprehensive and user-friendly. By prompting users for specific details, it avoids potential misconfigurations and simplifies the initial setup process. The code looks clean and maintains consistent formatting and encapsulation.

Code feedback

  • relevant file: pkg/app/pipectl/cmd/initialize/kubernetes.go
    suggestion: Consider validation for user input during the configuration process. For strings that represent URLs, versions, or paths, ensuring that they are well-formed before proceeding can mitigate runtime issues. For instance, adding checks to ensure that chartRepository is a valid URL or helmVersion matches expected version patterns would be beneficial. (medium)
    relevant line: + chartRepository string

  • relevant file: pkg/app/pipectl/cmd/initialize/kubernetes.go
    suggestion: Typos in method names can make it difficult for others to understand and maintain the code. Correct the typo in helmImput to helmInput. This is a simple but important fix for code maintainability. (important)
    relevant line: +func helmImput(p prompt.Prompt) (*config.KubernetesDeploymentInput, error) {

  • relevant file: pkg/app/pipectl/cmd/initialize/initialize.go
    suggestion: Removing the panic and providing an implementation for the Kubernetes platform is good. However, it might be beneficial to check whether err is not nil after calling generateKubernetesConfig(p) and handle the error accordingly before proceeding. (medium)
    relevant line: + cfg, err = generateKubernetesConfig(p)

Security concerns:

no

The added functionality does not seem to introduce any direct security concerns. User inputs are used to generate configuration, which is less likely to be a security threat in the context of initial setup scripts. However, it is always good to validate and sanitize any user inputs to prevent potential security issues in the future.

Signed-off-by: t-kikuc <[email protected]>
Copy link
Member

@ffjlabo ffjlabo left a comment

Choose a reason for hiding this comment

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

Sorry for the late review 🙏 I added some comments.

return nil, err
}

if len(chartRepository) > 0 {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if len(chartRepository) > 0 {
if chartRepository != "" {

Comment on lines 185 to 197
if len(chartRepository) > 0 {
// Use remote chart
err = p.RunSlice(remoteChartInputs)
if err != nil {
return nil, err
}
} else {
// Use local chart
err = p.RunSlice(localChartInputs)
if err != nil {
return nil, err
}
}
Copy link
Member

Choose a reason for hiding this comment

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

[nit] It would be nice to define the remoteChartInputs and localChartInputs in each if statement to minimize their scope. 👀

Comment on lines 94 to 102
inputs := []prompt.Input{
{
Message: "Kustomize version",
TargetPointer: &kustomizeVersion,
Required: false,
},
}

err := p.RunSlice(inputs)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
inputs := []prompt.Input{
{
Message: "Kustomize version",
TargetPointer: &kustomizeVersion,
Required: false,
},
}
err := p.RunSlice(inputs)
input := prompt.Input{
Message: "Kustomize version",
TargetPointer: &kustomizeVersion,
Required: false,
}
err := p.Run(input)

case helm:
deploymentInput, err = helmInput(p)
default:
return nil, errors.New("invalid number")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return nil, errors.New("invalid number")
return nil, fmt.Errorf("invalid manifest manager: %s", manifestManager)

Signed-off-by: t-kikuc <[email protected]>
@t-kikuc
Copy link
Member Author

t-kikuc commented Feb 16, 2024

@ffjlabo
Thank you so much! I fixed all above.

Copy link
Member

@ffjlabo ffjlabo left a comment

Choose a reason for hiding this comment

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

LGTM 👌

@t-kikuc t-kikuc enabled auto-merge (squash) February 16, 2024 05:02
@t-kikuc
Copy link
Member Author

t-kikuc commented Feb 21, 2024

@khanhtc1202 Would you check this? (not in a hurry)

Copy link
Member

@khanhtc1202 khanhtc1202 left a comment

Choose a reason for hiding this comment

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

Let's go 🚀
(sorry I missed this one 🙏 )

@t-kikuc t-kikuc merged commit 9a298a8 into master Feb 24, 2024
14 checks passed
@t-kikuc t-kikuc deleted the pipectl-init-k8s branch February 24, 2024 14:26
@github-actions github-actions bot mentioned this pull request Apr 8, 2024
@t-kikuc t-kikuc mentioned this pull request Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support K8sApp by pipectl init in simplest
3 participants