Skip to content
Merged
8 changes: 6 additions & 2 deletions cf-custom-resources/lib/env-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,11 @@ const controlEnv = async function (
(param) => !envSet.has(param)
);
const exportedValues = getExportedValues(updatedEnvStack);
// Return if there are no parameter changes.
// If there are no changes in env-controller managed parameters, the custom
// resource may have been triggered because the env template is upgraded,
// and the service template is attempting to retrieve the latest Outputs
// from the env stack (see PR #3957). Return the updated Outputs instead
// of triggering an env-controller update of the environment.
const shouldUpdateAliases = needUpdateAliases(envParams, workload, aliases);
if (
parametersToRemove.length + parametersToAdd.length === 0 &&
Expand Down Expand Up @@ -314,7 +318,7 @@ const getExportedValues = function (stack) {
const exportedValues = {};
stack.Outputs.forEach((output) => {
if (ignoredEnvOutputs.has(output.OutputKey)) {
return
return;
Comment thread
dannyrandall marked this conversation as resolved.
}
exportedValues[output.OutputKey] = output.OutputValue;
});
Expand Down
23 changes: 16 additions & 7 deletions internal/pkg/cli/deploy/svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ type workloadDeployer struct {
endpointGetter endpointGetter
spinner spinner
templateFS template.Reader
envVersionGetter versionGetter

// Cached variables.
defaultSess *session.Session
Expand All @@ -183,13 +184,14 @@ type workloadDeployer struct {

// WorkloadDeployerInput is the input to for workloadDeployer constructor.
type WorkloadDeployerInput struct {
SessionProvider *sessions.Provider
Name string
App *config.Application
Env *config.Environment
ImageTag string
Mft interface{} // Interpolated, applied, and unmarshaled manifest.
RawMft []byte // Content of the manifest file without any transformations.
SessionProvider *sessions.Provider
Name string
App *config.Application
Env *config.Environment
ImageTag string
Mft interface{} // Interpolated, applied, and unmarshaled manifest.
RawMft []byte // Content of the manifest file without any transformations.
EnvVersionGetter versionGetter
}

// newWorkloadDeployer is the constructor for workloadDeployer.
Expand Down Expand Up @@ -269,6 +271,7 @@ func newWorkloadDeployer(in *WorkloadDeployerInput) (*workloadDeployer, error) {
endpointGetter: envDescriber,
spinner: termprogress.NewSpinner(log.DiagnosticWriter),
templateFS: template.New(),
envVersionGetter: in.EnvVersionGetter,

defaultSess: defaultSession,
defaultSessWithEnvRegion: defaultSessEnvRegion,
Expand Down Expand Up @@ -991,6 +994,10 @@ func (d *workloadDeployer) runtimeConfig(in *StackRuntimeConfiguration) (*stack.
if err != nil {
return nil, fmt.Errorf("get service discovery endpoint: %w", err)
}
envVersion, err := d.envVersionGetter.Version()
if err != nil {
return nil, fmt.Errorf("get version of environment %q: %w", d.env.Name, err)
}
if in.ImageDigest == nil {
return &stack.RuntimeConfig{
AddonsTemplateURL: in.AddonsURL,
Expand All @@ -1000,6 +1007,7 @@ func (d *workloadDeployer) runtimeConfig(in *StackRuntimeConfiguration) (*stack.
AccountID: d.env.AccountID,
Region: d.env.Region,
CustomResourcesURL: in.CustomResourceURLs,
EnvVersion: envVersion,
}, nil
}
return &stack.RuntimeConfig{
Expand All @@ -1015,6 +1023,7 @@ func (d *workloadDeployer) runtimeConfig(in *StackRuntimeConfiguration) (*stack.
AccountID: d.env.AccountID,
Region: d.env.Region,
CustomResourcesURL: in.CustomResourceURLs,
EnvVersion: envVersion,
}, nil
}

Expand Down
148 changes: 103 additions & 45 deletions internal/pkg/cli/deploy/svc_test.go

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions internal/pkg/cli/job_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,14 @@ func newJobDeployer(o *deployJobOpts) (workloadDeployer, error) {
}
content := o.appliedDynamicMft.Manifest()
in := deploy.WorkloadDeployerInput{
SessionProvider: o.sessProvider,
Name: o.name,
App: o.targetApp,
Env: o.targetEnv,
ImageTag: o.imageTag,
Mft: content,
RawMft: raw,
SessionProvider: o.sessProvider,
Name: o.name,
App: o.targetApp,
Env: o.targetEnv,
ImageTag: o.imageTag,
Mft: content,
RawMft: raw,
EnvVersionGetter: o.envFeaturesDescriber,
}
var deployer workloadDeployer
switch t := content.(type) {
Expand Down
15 changes: 8 additions & 7 deletions internal/pkg/cli/svc_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,14 @@ func newSvcDeployer(o *deploySvcOpts) (workloadDeployer, error) {
content := o.appliedDynamicMft.Manifest()
var deployer workloadDeployer
in := clideploy.WorkloadDeployerInput{
SessionProvider: o.sessProvider,
Name: o.name,
App: targetApp,
Env: o.targetEnv,
ImageTag: o.imageTag,
Mft: content,
RawMft: raw,
SessionProvider: o.sessProvider,
Name: o.name,
App: targetApp,
Env: o.targetEnv,
ImageTag: o.imageTag,
Mft: content,
RawMft: raw,
EnvVersionGetter: o.envFeaturesDescriber,
}
switch t := content.(type) {
case *manifest.LoadBalancedWebService:
Expand Down
16 changes: 16 additions & 0 deletions internal/pkg/cli/svc_deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,22 @@ func TestSvcDeployOpts_Execute(t *testing.T) {

wantedError: fmt.Errorf("deploy service frontend to environment prod-iad: some error"),
},
"success with no recommendations": {
mock: func(m *deployMocks) {
m.mockWsReader.EXPECT().ReadWorkloadManifest(mockSvcName).Return([]byte(""), nil)
m.mockInterpolator.EXPECT().Interpolate("").Return("", nil)
m.mockMft = &mockWorkloadMft{
mockRequiredEnvironmentFeatures: func() []string {
return []string{"mockFeature1"}
},
}
m.mockEnvFeaturesDescriber.EXPECT().AvailableFeatures().Return([]string{"mockFeature1", "mockFeature2"}, nil)
m.mockEnvFeaturesDescriber.EXPECT().Version().Times(0)
m.mockDeployer.EXPECT().UploadArtifacts().Return(&deploy.UploadArtifactsOutput{}, nil)
m.mockDeployer.EXPECT().DeployWorkload(gomock.Any()).Return(nil, nil)
m.mockDeployer.EXPECT().IsServiceAvailableInRegion("").Return(false, nil)
},
},
}

for name, tc := range testCases {
Expand Down
15 changes: 8 additions & 7 deletions internal/pkg/cli/svc_package.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,14 @@ func newWorkloadStackGenerator(o *packageSvcOpts) (workloadStackGenerator, error
content := o.appliedDynamicMft.Manifest()
var deployer workloadStackGenerator
in := clideploy.WorkloadDeployerInput{
SessionProvider: o.sessProvider,
Name: o.name,
App: targetApp,
Env: targetEnv,
ImageTag: o.tag,
Mft: content,
RawMft: raw,
SessionProvider: o.sessProvider,
Name: o.name,
App: targetApp,
Env: targetEnv,
ImageTag: o.tag,
Mft: content,
RawMft: raw,
EnvVersionGetter: o.envFeaturesDescriber,
}
switch t := content.(type) {
case *manifest.LoadBalancedWebService:
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/deploy/cloudformation/stack/backend_svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ func (s *BackendService) Template() (string, error) {
EnvName: s.env,
WorkloadName: s.name,
SerializedManifest: string(s.rawManifest),
EnvVersion: s.rc.EnvVersion,

Variables: s.manifest.BackendServiceConfig.Variables,
Secrets: convertSecrets(s.manifest.BackendServiceConfig.Secrets),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,7 @@ func TestBackendService_TemplateAndParamsGeneration(t *testing.T) {
Manifest: mft.(*manifest.BackendService),
RuntimeConfig: RuntimeConfig{
ServiceDiscoveryEndpoint: fmt.Sprintf("%s.%s.local", envName, appName),
EnvVersion: "v1.42.0",
},
})
require.NoError(t, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func TestGrpcLoadBalancedWebService_Template(t *testing.T) {
ServiceDiscoveryEndpoint: svcDiscoveryEndpointName,
AccountID: "123456789123",
Region: "us-west-2",
EnvVersion: "v1.42.0",
},
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ func TestNetworkLoadBalancedWebService_Template(t *testing.T) {
ServiceDiscoveryEndpoint: svcDiscoveryEndpointName,
AccountID: "123456789123",
Region: "us-west-2",
EnvVersion: "v1.42.0",
},
RootUserARN: "arn:aws:iam::123456789123:root",
}, stack.WithNLB([]string{"10.0.0.0/24", "10.1.0.0/24"}))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func TestLoadBalancedWebService_Template(t *testing.T) {
ServiceDiscoveryEndpoint: svcDiscoveryEndpointName,
AccountID: "123456789123",
Region: "us-west-2",
EnvVersion: "v1.42.0",
},
})
tpl, err := serializer.Template()
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/deploy/cloudformation/stack/lb_web_svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ func (s *LoadBalancedWebService) Template() (string, error) {
EnvName: s.env,
WorkloadName: s.name,
SerializedManifest: string(s.rawManifest),
EnvVersion: s.rc.EnvVersion,

Variables: s.manifest.TaskConfig.Variables,
Secrets: convertSecrets(s.manifest.TaskConfig.Secrets),
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/deploy/cloudformation/stack/rd_web_svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ func (s *RequestDrivenWebService) Template() (string, error) {
EnvName: s.env,
WorkloadName: s.name,
SerializedManifest: string(s.rawManifest),
EnvVersion: s.rc.EnvVersion,

Variables: s.manifest.Variables,
StartCommand: s.manifest.StartCommand,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ func TestRDWS_Template(t *testing.T) {
Env: tc.envName,
Manifest: v,
RuntimeConfig: stack.RuntimeConfig{
AccountID: "123456789123",
Region: "us-west-2",
AccountID: "123456789123",
Region: "us-west-2",
EnvVersion: "v1.42.0",
},
})
require.NoError(t, err, "create rdws serializer")
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/deploy/cloudformation/stack/scheduled_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ func (j *ScheduledJob) Template() (string, error) {
ServiceDiscoveryEndpoint: j.rc.ServiceDiscoveryEndpoint,
Publish: publishers,
Platform: convertPlatform(j.manifest.Platform),
EnvVersion: j.rc.EnvVersion,

CustomResources: crs,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func TestScheduledJob_Template(t *testing.T) {
Manifest: v,
RuntimeConfig: stack.RuntimeConfig{
ServiceDiscoveryEndpoint: "test.my-app.local",
EnvVersion: "v1.42.0",
},
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func Test_Stack_Local_Integration(t *testing.T) {
RepoURL: imageURL,
ImageTag: imageTag,
},
EnvVersion: "v1.42.0",
},
})
require.NoError(t, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ Resources:
Workload: !Ref WorkloadName
EnvStack: !Sub "${AppName}-${EnvName}"
Parameters: ["InternalALBWorkloads"]
EnvVersion: v1.42.0
EnvControllerFunction:
Type: AWS::Lambda::Function
Properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ Resources:
Workload: !Ref WorkloadName
EnvStack: !Sub "${AppName}-${EnvName}"
Parameters: ["InternalALBWorkloads"]
EnvVersion: v1.42.0
EnvControllerFunction:
Type: AWS::Lambda::Function
Properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ Resources:
Workload: !Ref WorkloadName
EnvStack: !Sub "${AppName}-${EnvName}"
Parameters: ["InternalALBWorkloads"]
EnvVersion: v1.42.0
EnvControllerFunction:
Type: AWS::Lambda::Function
Properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ Resources:
Aliases: ["example.com", "foobar.com", "*.foobar.com"]
EnvStack: !Sub '${AppName}-${EnvName}'
Parameters: [InternalALBWorkloads]
EnvVersion: v1.42.0
EnvControllerFunction:
Type: AWS::Lambda::Function
Properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ Resources:
Workload: !Ref WorkloadName
EnvStack: !Sub "${AppName}-${EnvName}"
Parameters: []
EnvVersion: v1.42.0
EnvControllerFunction:
Type: AWS::Lambda::Function
Properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Resources:
EnvStack: !Sub '${AppName}-${EnvName}'
Parameters:
- EFSWorkloads
EnvVersion: v1.42.0

EnvControllerFunction:
Type: AWS::Lambda::Function
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ Resources:
Workload: !Ref WorkloadName
EnvStack: !Sub '${AppName}-${EnvName}'
Parameters: [NATWorkloads,]
EnvVersion: v1.42.0

EnvControllerFunction:
Type: AWS::Lambda::Function
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ Resources: # If a bucket URL is specified, that means the template exists.
Aliases: ["example.com"]
EnvStack: !Sub '${AppName}-${EnvName}'
Parameters: [ALBWorkloads, Aliases]
EnvVersion: v1.42.0
EnvControllerFunction:
Type: AWS::Lambda::Function
Properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ Resources: # If a bucket URL is specified, that means the template exists.
Workload: !Ref WorkloadName
EnvStack: !Sub '${AppName}-${EnvName}'
Parameters: [ALBWorkloads, Aliases]
EnvVersion: v1.42.0
EnvControllerFunction:
Type: AWS::Lambda::Function
Properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ Resources: # If a bucket URL is specified, that means the template exists.
Workload: !Ref WorkloadName
EnvStack: !Sub '${AppName}-${EnvName}'
Parameters: [Aliases]
EnvVersion: v1.42.0
EnvControllerFunction:
Type: AWS::Lambda::Function
Properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ Resources: # If a bucket URL is specified, that means the template exists.
Workload: !Ref WorkloadName
EnvStack: !Sub '${AppName}-${EnvName}'
Parameters: [Aliases]
EnvVersion: v1.42.0
EnvControllerFunction:
Type: AWS::Lambda::Function
Properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ Resources: # If a bucket URL is specified, that means the template exists.
Aliases: ["example.com"]
EnvStack: !Sub '${AppName}-${EnvName}'
Parameters: [ALBWorkloads, Aliases]
EnvVersion: v1.42.0
EnvControllerFunction:
Type: AWS::Lambda::Function
Properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ Resources: # If a bucket URL is specified, that means the template exists.
Aliases: ["example.com"]
EnvStack: !Sub '${AppName}-${EnvName}'
Parameters: [ALBWorkloads, Aliases]
EnvVersion: v1.42.0
EnvControllerFunction:
Type: AWS::Lambda::Function
Properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ Resources: # If a bucket URL is specified, that means the template exists.
Aliases: ["example.com"]
EnvStack: !Sub '${AppName}-${EnvName}'
Parameters: [ALBWorkloads, Aliases]
EnvVersion: v1.42.0
EnvControllerFunction:
Type: AWS::Lambda::Function
Properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ Resources: # If a bucket URL is specified, that means the template exists.
Workload: !Ref WorkloadName
EnvStack: !Sub '${AppName}-${EnvName}'
Parameters: [ALBWorkloads, Aliases]
EnvVersion: v1.42.0
EnvControllerFunction:
Type: AWS::Lambda::Function
Properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,7 @@ Resources:
Workload: !Ref WorkloadName
EnvStack: !Sub '${AppName}-${EnvName}'
Parameters: []
EnvVersion: v1.42.0
EnvControllerFunction:
Type: AWS::Lambda::Function
Properties:
Expand Down
Loading