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

feat: add cli plan command #219

Closed
wants to merge 31 commits into from
Closed

feat: add cli plan command #219

wants to merge 31 commits into from

Conversation

okysetiawan
Copy link

@okysetiawan okysetiawan commented May 3, 2024

Description

  • support command job plan
  • support command resource plan
  • command job & resource plan have 4 operation:
    • create
    • update
    • delete
    • migrate (change namespace and update)

Support Git Integration

@okysetiawan okysetiawan self-assigned this May 3, 2024
@okysetiawan okysetiawan marked this pull request as ready for review May 6, 2024 05:38
OperationUpdate
)

func (o Operation) String() string {

Choose a reason for hiding this comment

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

how are we handling migrate

Copy link
Author

Choose a reason for hiding this comment

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

we will handling migrate using plan.Compositor to merge migrate operation (change namespace and update on apply command) between create and delete operation

}

jobPlan = &plan.Plan{ProjectName: p.clientConfig.Project.Name, NamespaceName: namespaceName, Kind: plan.KindJob}
if len(sourceSpec.Name) == 0 && len(destinationSpec.Name) > 0 {

Choose a reason for hiding this comment

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

want to understand this logic better

Copy link
Author

Choose a reason for hiding this comment

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

updated the implementation using method as logic description

Copy link
Member

@deryrahman deryrahman 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 make the diff operation can also be useful in local env, not calling to remote api

client/cmd/resource/plan.go Outdated Show resolved Hide resolved
client/cmd/job/plan.go Show resolved Hide resolved
client/cmd/job/plan.go Show resolved Hide resolved
client/extension/provider/gitlab/api.go Outdated Show resolved Hide resolved
client/cmd/internal/plan/operation.go Outdated Show resolved Hide resolved
client/cmd/internal/plan/plan.go Outdated Show resolved Hide resolved
}

func (p *planCommand) saveFile(plans plan.Plans) error {
file, err := os.OpenFile(p.output, unix.O_RDWR|unix.O_CREAT, os.ModePerm)
Copy link
Member

Choose a reason for hiding this comment

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

windows environment might not understand this unix package, can we use os.O_RDWR|os.O_CREATE instead?

Copy link
Member

Choose a reason for hiding this comment

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

we can also use TRUNC mode to avoid manual file truncate. we could use os.O_TRUNC

directories := providermodel.Diffs(diffs).GetAllDirectories(p.appendDirectory)
p.logger.Info("job plan found changed in directories: %+v", directories)

var plans plan.Plans

Choose a reason for hiding this comment

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

you can encapsulate creation of plans from directories into a single function

return p.saveFile(mergedPlans)
}

func (p *planCommand) describePlanFromDirectory(ctx context.Context, directory string) (*plan.Plan, error) {

Choose a reason for hiding this comment

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

what does describe mean?

return nil
}

func (p *planCommand) RunE(_ *cobra.Command, _ []string) error {

Choose a reason for hiding this comment

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

As discussed imo, plan command should not have the logic of plan, it should just invoke the functionality implemented in the plan struct.

Choose a reason for hiding this comment

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

and see if we can create smaller functions & tie them together

return p.saveFile(mergedPlans)
}

func (p *planCommand) describePlanFromDirectory(ctx context.Context, directory string) (*plan.Plan, error) {

Choose a reason for hiding this comment

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

see if we break it down to smaller functions, the for loops & if else conditions normally we can look into keeping into smaller private functions & we can avoid if else chaining

return len(sourceSpec.Name) > 0 && len(destinationSpec.Name) == 0
}

func (*planCommand) appendDirectory(directory string, directoryExists map[string]bool, fileDirectories []string) []string {

Choose a reason for hiding this comment

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

what is the purpose of this appendDirectory can we have this function with a business meaning

@@ -0,0 +1,26 @@
package model

type Diff struct {

Choose a reason for hiding this comment

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

what is the purpose of this struct

@okysetiawan
Copy link
Author

closing this PR, moving to #228

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants