Skip to content

Commit

Permalink
Add sync-awsapplicationloadbalancerconfig command
Browse files Browse the repository at this point in the history
  • Loading branch information
mumoshu committed Nov 13, 2021
1 parent 6cdeecc commit b767692
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cmd/okra/okra.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,8 @@ func Run() error {
listLatestTargetGroupsInput = InitListLatestAWSTargetGroupsFlags(listLatestTargetGroups.Flags(), &awstargetgroupset.ListLatestAWSTargetGroupsInput{})
cmd.AddCommand(listLatestTargetGroups)

cmd.AddCommand(newSyncAWSApplicationLoadBalancerConfigCommand())

var runAnalysisInput func() *analysis.RunInput
runAnalysis := &cobra.Command{
Use: "run-analysis",
Expand Down
50 changes: 50 additions & 0 deletions cmd/okra/sync_awsapplicationloadbalancerconfig.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package okra

import (
okrav1alpha1 "github.com/mumoshu/okra/api/v1alpha1"
"github.com/mumoshu/okra/pkg/awsapplicationloadbalancer"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)

func newSyncAWSApplicationLoadBalancerConfigCommand() *cobra.Command {
var syncInput func() *awsapplicationloadbalancer.SyncInput
cmd := &cobra.Command{
Use: "sync-awsapplicationloadbalancerconfig",
RunE: func(cmd *cobra.Command, args []string) error {
err := awsapplicationloadbalancer.Sync(*syncInput())
return err
},
}
syncInput = initSyncAWSApplicationLoadBalancerConfigFlags(cmd.Flags(), &awsapplicationloadbalancer.SyncInput{})
return cmd
}

func initSyncAWSApplicationLoadBalancerConfigFlags(flag *pflag.FlagSet, c *awsapplicationloadbalancer.SyncInput) func() *awsapplicationloadbalancer.SyncInput {
var (
tg1, tg2 okrav1alpha1.ForwardTargetGroup
)

flag.StringVar(&c.Region, "region", "", "AWS region where the target ALB is in")
flag.StringVar(&c.Profile, "profile", "", "AWS profile that is used to access the target ALB")
flag.StringVar(&c.Address, "address", "", "Custom address of AWS API endpoint that is used when testing")
flag.StringVar(&c.Spec.ListenerARN, "listener-arn", "", "ARN of the AWS ALB Listener on which the Listener Rule for traffic management is created")
flag.IntVar(&c.Spec.Listener.Rule.Priority, "listener-rule-priority", 0, "Priority of the ALB Listener Rule that is used as a unique ID of it")
flag.StringVar(&tg1.ARN, "target-group-1-arn", "", "ARN of the first target group")
flag.IntVar(&tg1.Weight, "target-group-1-weight", 50, "Weight of the first target group")
flag.StringVar(&tg2.ARN, "target-group-2-arn", "", "ARN of the second target group")
flag.IntVar(&tg2.Weight, "target-group-2-weight", 50, "Weight of the second target group")

return func() *awsapplicationloadbalancer.SyncInput {
tg1.Name = "first"
tg2.Name = "second"

spec := c.Spec.DeepCopy()
spec.Listener.Rule.Forward.TargetGroups = append(spec.Listener.Rule.Forward.TargetGroups, tg1, tg2)

input := c
input.Spec = *spec

return input
}
}

0 comments on commit b767692

Please sign in to comment.