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

chore(manifest): add advanced types validation I #2852

Merged
merged 5 commits into from
Sep 21, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion internal/pkg/cli/job_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,11 @@ func (o *initJobOpts) Execute() error {
return err
}
o.platform = platform
var platformStrPtr *manifest.PlatformString
if o.platform != nil {
log.Warningf("Your architecture type is currently unsupported. Setting platform to %s in your manifest.\n", dockerengine.DockerBuildPlatform(dockerengine.LinuxOS, dockerengine.Amd64Arch))
val := manifest.PlatformString(*o.platform)
platformStrPtr = &val
}

manifestPath, err := o.init.Job(&initialize.JobProps{
Expand All @@ -208,7 +211,7 @@ func (o *initJobOpts) Execute() error {
DockerfilePath: o.dockerfilePath,
Image: o.image,
Platform: manifest.PlatformArgsOrString{
PlatformString: o.platform,
PlatformString: platformStrPtr,
},
},

Expand Down
5 changes: 4 additions & 1 deletion internal/pkg/cli/svc_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,14 @@ func (o *initSvcOpts) Execute() error {
return fmt.Errorf("get/redirect docker engine platform: %w", err)
}
o.platform = platform
var platformStrPtr *manifest.PlatformString
if o.platform != nil {
log.Warningf("Your architecture type is currently unsupported. Setting platform %s instead.\n", dockerengine.DockerBuildPlatform(dockerengine.LinuxOS, dockerengine.Amd64Arch))
if o.wkldType != manifest.RequestDrivenWebServiceType {
log.Warning("See 'platform' field in your manifest.\n")
}
val := manifest.PlatformString(*o.platform)
platformStrPtr = &val
}

manifestPath, err := o.init.Service(&initialize.ServiceProps{
Expand All @@ -276,7 +279,7 @@ func (o *initSvcOpts) Execute() error {
DockerfilePath: o.dockerfilePath,
Image: o.image,
Platform: manifest.PlatformArgsOrString{
PlatformString: o.platform,
PlatformString: platformStrPtr,
},
Topics: o.topics,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ Outputs:

if tc.setUpManifest != nil {
tc.setUpManifest(conf)
conf.manifest.Network.VPC.Placement = aws.String(manifest.PrivateSubnetPlacement)
privatePlacement := manifest.Placement(manifest.PrivateSubnetPlacement)
conf.manifest.Network.VPC.Placement = &privatePlacement
conf.manifest.Network.VPC.SecurityGroups = []string{"sg-1234"}
}

Expand Down
5 changes: 4 additions & 1 deletion internal/pkg/deploy/cloudformation/stack/lb_web_svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,10 @@ func (s *LoadBalancedWebService) Template() (string, error) {
deregistrationDelay = aws.Int64(int64(s.manifest.RoutingRule.DeregistrationDelay.Seconds()))
}

allowedSourceIPs := s.manifest.AllowedSourceIps
var allowedSourceIPs []string
for _, ipNet := range s.manifest.AllowedSourceIps {
allowedSourceIPs = append(allowedSourceIPs, string(ipNet))
}
content, err := s.parser.ParseLoadBalancedWebService(template.WorkloadOpts{
Variables: s.manifest.Variables,
Secrets: s.manifest.Secrets,
Expand Down
5 changes: 4 additions & 1 deletion internal/pkg/deploy/cloudformation/stack/transformers.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,10 @@ func convertNetworkConfig(network manifest.NetworkConfig) *template.NetworkOpts
SubnetsType: template.PublicSubnetsPlacement,
SecurityGroups: network.VPC.SecurityGroups,
}
if aws.StringValue(network.VPC.Placement) != manifest.PublicSubnetPlacement {
if network.VPC.Placement == nil {
return opts
}
if *network.VPC.Placement != manifest.PublicSubnetPlacement {
opts.AssignPublicIP = template.DisablePublicIP
opts.SubnetsType = template.PrivateSubnetsPlacement
}
Expand Down
25 changes: 15 additions & 10 deletions internal/pkg/deploy/cloudformation/stack/transformers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ func Test_convertSidecar(t *testing.T) {

func Test_convertAdvancedCount(t *testing.T) {
mockRange := manifest.IntRangeBand("1-10")
mockPerc := manifest.Percentage(70)
testCases := map[string]struct {
input *manifest.AdvancedCount
expected *template.AdvancedCount
Expand Down Expand Up @@ -335,7 +336,7 @@ func Test_convertAdvancedCount(t *testing.T) {
Range: manifest.Range{
Value: &mockRange,
},
CPU: aws.Int(70),
CPU: &mockPerc,
},
expected: &template.AdvancedCount{
Autoscaling: &template.AutoscalingOpts{
Expand All @@ -354,7 +355,7 @@ func Test_convertAdvancedCount(t *testing.T) {
SpotFrom: aws.Int(5),
},
},
CPU: aws.Int(70),
CPU: &mockPerc,
},
expected: &template.AdvancedCount{
Autoscaling: &template.AutoscalingOpts{
Expand Down Expand Up @@ -486,10 +487,14 @@ func Test_convertCapacityProviders(t *testing.T) {
}

func Test_convertAutoscaling(t *testing.T) {
mockRange := manifest.IntRangeBand("1-100")
badRange := manifest.IntRangeBand("badRange")
mockRequests := 1000
mockResponseTime := 512 * time.Millisecond
var (
mockRange = manifest.IntRangeBand("1-100")
badRange = manifest.IntRangeBand("badRange")
mockRequests = 1000
mockResponseTime = 512 * time.Millisecond
mockCPU = manifest.Percentage(70)
mockMem = manifest.Percentage(80)
)

testAcceptableLatency := 10 * time.Minute
testAvgProcessingTime := 250 * time.Millisecond
Expand All @@ -513,8 +518,8 @@ func Test_convertAutoscaling(t *testing.T) {
Range: manifest.Range{
Value: &mockRange,
},
CPU: aws.Int(70),
Memory: aws.Int(80),
CPU: &mockCPU,
Memory: &mockMem,
Requests: aws.Int(mockRequests),
ResponseTime: &mockResponseTime,
},
Expand All @@ -537,8 +542,8 @@ func Test_convertAutoscaling(t *testing.T) {
SpotFrom: aws.Int(5),
},
},
CPU: aws.Int(70),
Memory: aws.Int(80),
CPU: &mockCPU,
Memory: &mockMem,
Requests: aws.Int(mockRequests),
ResponseTime: &mockResponseTime,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ Outputs:

if tc.setUpManifest != nil {
tc.setUpManifest(conf)
conf.manifest.Network.VPC.Placement = aws.String(manifest.PrivateSubnetPlacement)
conf.manifest.Network.VPC.Placement = &manifest.PrivateSubnetPlacement
conf.manifest.Network.VPC.SecurityGroups = []string{"sg-1234"}
}

Expand Down
16 changes: 8 additions & 8 deletions internal/pkg/manifest/applyenv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,28 +525,28 @@ func TestApplyEnv_StringSlice(t *testing.T) {
}{
"string slice overridden": {
inSvc: func(svc *LoadBalancedWebService) {
svc.RoutingRule.AllowedSourceIps = []string{"walk", "like", "an", "egyptian"}
svc.Environments["test"].RoutingRule.AllowedSourceIps = []string{"walk", "on", "the", "wild", "side"}
svc.ImageConfig.HealthCheck.Command = []string{"walk", "like", "an", "egyptian"}
svc.Environments["test"].ImageConfig.HealthCheck.Command = []string{"walk", "on", "the", "wild", "side"}
},
wanted: func(svc *LoadBalancedWebService) {
svc.RoutingRule.AllowedSourceIps = []string{"walk", "on", "the", "wild", "side"}
svc.ImageConfig.HealthCheck.Command = []string{"walk", "on", "the", "wild", "side"}
},
},
"string slice overridden by zero value": {
inSvc: func(svc *LoadBalancedWebService) {
svc.RoutingRule.AllowedSourceIps = []string{"walk", "like", "an", "egyptian"}
svc.Environments["test"].RoutingRule.AllowedSourceIps = []string{}
svc.ImageConfig.HealthCheck.Command = []string{"walk", "like", "an", "egyptian"}
svc.Environments["test"].ImageConfig.HealthCheck.Command = []string{}
},
wanted: func(svc *LoadBalancedWebService) {
svc.RoutingRule.AllowedSourceIps = []string{}
svc.ImageConfig.HealthCheck.Command = []string{}
},
},
"string slice not overridden": {
inSvc: func(svc *LoadBalancedWebService) {
svc.RoutingRule.AllowedSourceIps = []string{"walk", "like", "an", "egyptian"}
svc.ImageConfig.HealthCheck.Command = []string{"walk", "like", "an", "egyptian"}
},
wanted: func(svc *LoadBalancedWebService) {
svc.RoutingRule.AllowedSourceIps = []string{"walk", "like", "an", "egyptian"}
svc.ImageConfig.HealthCheck.Command = []string{"walk", "like", "an", "egyptian"}
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/manifest/backend_svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func newDefaultBackendService() *BackendService {
},
Network: NetworkConfig{
VPC: vpcConfig{
Placement: stringP(PublicSubnetPlacement),
Placement: &PublicSubnetPlacement,
},
},
},
Expand Down
14 changes: 8 additions & 6 deletions internal/pkg/manifest/backend_svc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestNewBackendSvc(t *testing.T) {
},
Network: NetworkConfig{
VPC: vpcConfig{
Placement: stringP("public"),
Placement: &PublicSubnetPlacement,
},
},
},
Expand Down Expand Up @@ -102,7 +102,7 @@ func TestNewBackendSvc(t *testing.T) {
},
Network: NetworkConfig{
VPC: vpcConfig{
Placement: stringP("public"),
Placement: &PublicSubnetPlacement,
},
},
},
Expand Down Expand Up @@ -255,6 +255,7 @@ func TestBackendService_Publish(t *testing.T) {
}

func TestBackendSvc_ApplyEnv(t *testing.T) {
mockPercentage := Percentage(70)
mockBackendServiceWithNoEnvironments := BackendService{
Workload: Workload{
Name: aws.String("phonetool"),
Expand Down Expand Up @@ -366,7 +367,7 @@ func TestBackendSvc_ApplyEnv(t *testing.T) {
TaskConfig: TaskConfig{
Count: Count{
AdvancedCount: AdvancedCount{
CPU: aws.Int(70),
CPU: &mockPercentage,
},
},
CPU: aws.Int(512),
Expand Down Expand Up @@ -562,7 +563,7 @@ func TestBackendSvc_ApplyEnv(t *testing.T) {
Memory: aws.Int(256),
Count: Count{
AdvancedCount: AdvancedCount{
CPU: aws.Int(70),
CPU: &mockPercentage,
},
},
Variables: map[string]string{
Expand Down Expand Up @@ -689,6 +690,7 @@ func TestBackendSvc_ApplyEnv(t *testing.T) {

func TestBackendSvc_ApplyEnv_CountOverrides(t *testing.T) {
mockRange := IntRangeBand("1-10")
mockPercentage := Percentage(80)
testCases := map[string]struct {
svcCount Count
envCount Count
Expand All @@ -699,7 +701,7 @@ func TestBackendSvc_ApplyEnv_CountOverrides(t *testing.T) {
svcCount: Count{
AdvancedCount: AdvancedCount{
Range: Range{Value: &mockRange},
CPU: aws.Int(80),
CPU: &mockPercentage,
},
},
envCount: Count{},
Expand All @@ -709,7 +711,7 @@ func TestBackendSvc_ApplyEnv_CountOverrides(t *testing.T) {
Count: Count{
AdvancedCount: AdvancedCount{
Range: Range{Value: &mockRange},
CPU: aws.Int(80),
CPU: &mockPercentage,
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/manifest/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func newDefaultScheduledJob() *ScheduledJob {
},
Network: NetworkConfig{
VPC: vpcConfig{
Placement: stringP(PublicSubnetPlacement),
Placement: &PublicSubnetPlacement,
},
},
},
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/manifest/job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func TestScheduledJob_ApplyEnv(t *testing.T) {
},
Network: NetworkConfig{
VPC: vpcConfig{
Placement: stringP(PublicSubnetPlacement),
Placement: &PublicSubnetPlacement,
},
},
},
Expand Down Expand Up @@ -171,7 +171,7 @@ func TestScheduledJob_ApplyEnv(t *testing.T) {
},
Network: NetworkConfig{
VPC: vpcConfig{
Placement: stringP(PublicSubnetPlacement),
Placement: &PublicSubnetPlacement,
},
},
},
Expand Down
11 changes: 7 additions & 4 deletions internal/pkg/manifest/lb_web_svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func newDefaultLoadBalancedWebService() *LoadBalancedWebService {
},
Network: NetworkConfig{
VPC: vpcConfig{
Placement: stringP(PublicSubnetPlacement),
Placement: &PublicSubnetPlacement,
},
},
},
Expand Down Expand Up @@ -182,11 +182,14 @@ type RoutingRule struct {
Alias Alias `yaml:"alias"`
DeregistrationDelay *time.Duration `yaml:"deregistration_delay"`
// TargetContainer is the container load balancer routes traffic to.
TargetContainer *string `yaml:"target_container"`
TargetContainerCamelCase *string `yaml:"targetContainer"` // "targetContainerCamelCase" for backwards compatibility
AllowedSourceIps []string `yaml:"allowed_source_ips"`
TargetContainer *string `yaml:"target_container"`
TargetContainerCamelCase *string `yaml:"targetContainer"` // "targetContainerCamelCase" for backwards compatibility
AllowedSourceIps []IPNet `yaml:"allowed_source_ips"`
}

// IPNet represents an IP network string. For example: 10.1.0.0/16
type IPNet string

// Alias is a custom type which supports unmarshaling "http.alias" yaml which
// can either be of type string or type slice of string.
type Alias stringSliceOrString
Expand Down
Loading