Skip to content

Commit

Permalink
Merge branch 'main' into willdavsmith/env-app-name
Browse files Browse the repository at this point in the history
  • Loading branch information
willdavsmith authored Sep 27, 2023
2 parents 71bf2ae + 86ca6d8 commit b9abe71
Show file tree
Hide file tree
Showing 20 changed files with 363 additions and 108 deletions.
3 changes: 3 additions & 0 deletions cmd/applications-rp/portableresource-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,8 @@ ucp:
logging:
level: "info"
json: false
bicep:
deleteRetryCount: 20
deleteRetryDelaySeconds: 60
terraform:
path: "/terraform"
3 changes: 3 additions & 0 deletions cmd/applications-rp/portableresource-self-hosted.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,8 @@ ucp:
logging:
level: "info"
json: false
bicep:
deleteRetryCount: 20
deleteRetryDelaySeconds: 60
terraform:
path: "/tmp"
3 changes: 3 additions & 0 deletions cmd/applications-rp/radius-cloud.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,8 @@ ucp:
logging:
level: "info"
json: false
bicep:
deleteRetryCount: 20
deleteRetryDelaySeconds: 60
terraform:
path: "/terraform"
3 changes: 3 additions & 0 deletions cmd/applications-rp/radius-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,8 @@ ucp:
logging:
level: "info"
json: false
bicep:
deleteRetryCount: 20
deleteRetryDelaySeconds: 60
terraform:
path: "/terraform"
3 changes: 3 additions & 0 deletions cmd/applications-rp/radius-self-hosted.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,8 @@ tracerProvider:
serviceName: "applications.core"
zipkin:
url: "http://localhost:9411/api/v2/spans"
bicep:
deleteRetryCount: 20
deleteRetryDelaySeconds: 60
terraform:
path: "/tmp"
6 changes: 6 additions & 0 deletions deploy/Chart/templates/rp/configmaps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ data:
zipkin:
url: {{ .Values.global.zipkin.url }}
{{- end }}
bicep:
deleteRetryCount: 20
deleteRetryDelaySeconds: 60
terraform:
path: "/terraform"
Expand Down Expand Up @@ -98,5 +101,8 @@ data:
zipkin:
url: {{ .Values.global.zipkin.url }}
{{- end }}
bicep:
deleteRetryCount: 20
deleteRetryDelaySeconds: 60
terraform:
path: "/terraform"
3 changes: 3 additions & 0 deletions deploy/Chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,8 @@ rp:
# limit is higher for applications-rp because the Terraform execution
# can spike memory usage.
memory: "500Mi"
bicep:
deleteRetryCount: 20
deleteRetryDelaySeconds: 60
terraform:
path: "/terraform"
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ require (
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armsubscriptions v1.2.0
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/servicebus/armservicebus/v2 v2.0.0-beta.3
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage v1.3.0
github.com/Azure/go-autorest/autorest/to v0.4.0
github.com/Azure/secrets-store-csi-driver-provider-azure v1.4.1
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d
github.com/agnivade/levenshtein v1.1.1
Expand Down Expand Up @@ -104,7 +103,6 @@ require (
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230106234847-43070de90fa1 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 // indirect
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
github.com/AzureAD/microsoft-authentication-library-for-go v1.0.0 // indirect
github.com/BurntSushi/toml v1.2.1 // indirect
github.com/MakeNowJust/heredoc v1.0.0 // indirect
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage v1.3.0
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage v1.3.0/go.mod h1:+OgGVo0Httq7N5oayfvaLQ/Jq+2gJdqfp++Hyyl7Tws=
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8=
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
github.com/Azure/go-autorest v14.2.0+incompatible h1:V5VMDjClD3GiElqLWO7mz2MxNAK/vTfRHdAubSIPRgs=
github.com/Azure/go-autorest v14.2.0+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24=
github.com/Azure/go-autorest/autorest/to v0.4.0 h1:oXVqrxakqqV1UZdSazDOPOLvOIz+XA683u8EctwboHk=
github.com/Azure/go-autorest/autorest/to v0.4.0/go.mod h1:fE8iZBn7LQR7zH/9XU2NcPR4o9jEImooCeWJcYV/zLE=
github.com/Azure/secrets-store-csi-driver-provider-azure v1.4.1 h1:24/mZ06Uzu8EkdgJj8zcy5C3Ipsg1doM62hx0WPscNU=
github.com/Azure/secrets-store-csi-driver-provider-azure v1.4.1/go.mod h1:xUXKV8vOut59vIrFhyEY+4PgiK2LXkP10BtI+2y8VXM=
github.com/AzureAD/microsoft-authentication-library-for-go v1.0.0 h1:OBhqkivkhkMqLPymWEppkm7vgPQY2XsHoEkaMQ0AdZY=
Expand Down
9 changes: 9 additions & 0 deletions pkg/armrpc/hostoptions/providerconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type ProviderConfig struct {
ProfilerProvider profilerprovider.ProfilerProviderOptions `yaml:"profilerProvider"`
UCP config.UCPOptions `yaml:"ucp"`
Logging ucplog.LoggingOptions `yaml:"logging"`
Bicep BicepOptions `yaml:"bicep,omitempty"`
Terraform TerraformOptions `yaml:"terraform,omitempty"`

// FeatureFlags includes the list of feature flags.
Expand Down Expand Up @@ -70,6 +71,14 @@ type WorkerServerOptions struct {
MaxOperationRetryCount *int `yaml:"maxOperationRetryCount,omitempty"`
}

// BicepOptions includes options required for bicep execution.
type BicepOptions struct {
// DeleteRetryCount is the number of times to retry the request.
DeleteRetryCount string `yaml:"deleteRetryCount,omitempty"`
// DeleteRetryDelaySeconds is the delay between retries in seconds.
DeleteRetryDelaySeconds string `yaml:"deleteRetryDelaySeconds,omitempty"`
}

// TerraformOptions includes options required for terraform execution.
type TerraformOptions struct {
// Path is the path to the directory mounted to the container where terraform can be installed and executed.
Expand Down
6 changes: 6 additions & 0 deletions pkg/cli/clivalidation.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ func RequireEnvironmentName(cmd *cobra.Command, args []string, workspace workspa
return environmentName, err
}

// DidSpecifyEnvironmentName checks if an environment name is provided as a flag
func DidSpecifyEnvironmentName(cmd *cobra.Command, args []string) bool {
environmentName, err := cmd.Flags().GetString("environment")
return err == nil && environmentName != ""
}

// RequireKubeContext is used by commands that need a kubernetes context name to be specified using -c flag or has a default kubecontext
//

Expand Down
45 changes: 34 additions & 11 deletions pkg/cli/cmd/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,22 @@ func (r *Runner) Validate(cmd *cobra.Command, args []string) error {
return err
}
env, err := client.GetEnvDetails(cmd.Context(), r.EnvironmentName)
if clients.Is404Error(err) {
return clierrors.Message("The environment %q does not exist in scope %q. Run `rad env create` try again.", r.EnvironmentName, r.Workspace.Scope)
} else if err != nil {
return err
if err != nil {
// If the error is not a 404, return it
if !clients.Is404Error(err) {
return err
}

// If the environment doesn't exist, but the user specified it as
// a command-line option, return an error
if cli.DidSpecifyEnvironmentName(cmd, args) {
return clierrors.Message("The environment %q does not exist in scope %q. Run `rad env create` first.", r.EnvironmentName, r.Workspace.Scope)
}

// If we got here, it means that the error was a 404 and the user did not specify the environment name.
// This is fine, because an environment is not required.
}

r.Providers = &clients.Providers{}
r.Providers.Radius = &clients.RadiusProvider{}
r.Providers.Radius.EnvironmentID = r.Workspace.Scope + "/providers/applications.core/environments/" + r.EnvironmentName
Expand Down Expand Up @@ -243,14 +254,26 @@ func (r *Runner) Run(ctx context.Context) error {
return err
}

err = client.CreateApplicationIfNotFound(ctx, r.ApplicationName, v20231001preview.ApplicationResource{
Location: to.Ptr(v1.LocationGlobal),
Properties: &v20231001preview.ApplicationProperties{
Environment: &r.Workspace.Environment,
},
})
// Validate that the environment exists already
_, err = client.GetEnvDetails(ctx, r.EnvironmentName)
if err != nil {
return err
// If the error is not a 404, return it
if !clients.Is404Error(err) {
return err
}

// If the error is a 404, it means that the environment does not exist,
// but this is okay. We don't want to create an application though.
} else {
err = client.CreateApplicationIfNotFound(ctx, r.ApplicationName, v20231001preview.ApplicationResource{
Location: to.Ptr(v1.LocationGlobal),
Properties: &v20231001preview.ApplicationProperties{
Environment: &r.Workspace.Environment,
},
})
if err != nil {
return err
}
}
}

Expand Down
77 changes: 77 additions & 0 deletions pkg/cli/cmd/deploy/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,21 @@ func Test_Validate(t *testing.T) {
Config: radcli.LoadEmptyConfig(t),
},
},
{
Name: "rad deploy - missing env and app succeeds",
Input: []string{"app.bicep", "--group", "new-group"},
ExpectedValid: true,
ConfigHolder: framework.ConfigHolder{
ConfigFilePath: "",
Config: configWithWorkspace,
},
ConfigureMocks: func(mocks radcli.ValidateMocks) {
mocks.ApplicationManagementClient.EXPECT().
GetEnvDetails(gomock.Any(), gomock.Any()).
Return(v20231001preview.EnvironmentResource{}, radcli.Create404Error()).
Times(1)
},
},
}

radcli.SharedValidateValidation(t, NewCommand, testcases)
Expand Down Expand Up @@ -360,6 +375,10 @@ func Test_Run(t *testing.T) {
options := deploy.Options{}

appManagmentMock := clients.NewMockApplicationsManagementClient(ctrl)
appManagmentMock.EXPECT().
GetEnvDetails(gomock.Any(), radcli.TestEnvironmentName).
Return(v20231001preview.EnvironmentResource{}, nil).
Times(1)
appManagmentMock.EXPECT().
CreateApplicationIfNotFound(gomock.Any(), "test-application", gomock.Any()).
Return(nil).
Expand Down Expand Up @@ -414,4 +433,62 @@ func Test_Run(t *testing.T) {
// is always empty.
require.Empty(t, outputSink.Writes)
})

t.Run("Deployment that doesn't need an app or env", func(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

bicep := bicep.NewMockInterface(ctrl)
bicep.EXPECT().
PrepareTemplate("app.bicep").
Return(map[string]any{}, nil).
Times(1)

appManagmentMock := clients.NewMockApplicationsManagementClient(ctrl)

// GetEnvDetails returns a 404 error
appManagmentMock.EXPECT().
GetEnvDetails(gomock.Any(), "envdoesntexist").
Return(v20231001preview.EnvironmentResource{}, radcli.Create404Error()).
Times(1)

deployMock := deploy.NewMockInterface(ctrl)
deployMock.EXPECT().
DeployWithProgress(gomock.Any(), gomock.Any()).
DoAndReturn(func(ctx context.Context, o deploy.Options) (clients.DeploymentResult, error) {
return clients.DeploymentResult{}, nil
}).
Times(1)

workspace := &workspaces.Workspace{
Connection: map[string]any{
"kind": "kubernetes",
"context": "kind-kind",
},
Name: "kind-kind",
}
outputSink := &output.MockOutput{}

runner := &Runner{
Bicep: bicep,
ConnectionFactory: &connections.MockFactory{ApplicationsManagementClient: appManagmentMock},
Deploy: deployMock,
Output: outputSink,
Providers: nil,
FilePath: "app.bicep",
ApplicationName: "appdoesntexist",
EnvironmentName: "envdoesntexist",
Parameters: map[string]map[string]any{},
Workspace: workspace,
}

err := runner.Run(context.Background())

// Even though GetEnvDetails returns a 404 error, the deployment should still succeed
require.NoError(t, err)

// All of the output in this command is being done by functions that we mock for testing, so this
// is always empty.
require.Empty(t, outputSink.Writes)
})
}
4 changes: 4 additions & 0 deletions pkg/cli/cmd/run/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ func Test_Run(t *testing.T) {
}

clientMock := clients.NewMockApplicationsManagementClient(ctrl)
clientMock.EXPECT().
GetEnvDetails(gomock.Any(), "test-environment").
Return(v20231001preview.EnvironmentResource{}, nil).
Times(1)
clientMock.EXPECT().
CreateApplicationIfNotFound(gomock.Any(), "test-application", gomock.Any()).
Return(nil).
Expand Down
8 changes: 4 additions & 4 deletions pkg/datastoresrp/frontend/controller/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ const (
OperationListSecret = "LISTSECRETS"

// AsyncCreateOrUpdateMongoDatabaseTimeout is the timeout for async create or update Mongo database
AsyncCreateOrUpdateMongoDatabaseTimeout = time.Duration(10) * time.Minute
AsyncCreateOrUpdateMongoDatabaseTimeout = time.Duration(60) * time.Minute
// AsyncDeleteMongoDatabaseTimeout is the timeout for async delete Mongo database
AsyncDeleteMongoDatabaseTimeout = time.Duration(15) * time.Minute
AsyncDeleteMongoDatabaseTimeout = time.Duration(30) * time.Minute

// AsyncCreateOrUpdateRedisCacheTimeout is the timeout for async create or update Redis cache
AsyncCreateOrUpdateRedisCacheTimeout = time.Duration(60) * time.Minute
Expand All @@ -40,7 +40,7 @@ const (
AsyncDeleteDaprStateStoreTimeout = time.Duration(30) * time.Minute

// AsyncCreateOrUpdateSqlTimeout is the timeout for async create or update sql database
AsyncCreateOrUpdateSqlDatabaseTimeout = time.Duration(10) * time.Minute
AsyncCreateOrUpdateSqlDatabaseTimeout = time.Duration(60) * time.Minute
// AsyncDeleteSqlDatabaseTimeout is the timeout for async delete sql database
AsyncDeleteSqlDatabaseTimeout = time.Duration(15) * time.Minute
AsyncDeleteSqlDatabaseTimeout = time.Duration(30) * time.Minute
)
22 changes: 21 additions & 1 deletion pkg/recipes/controllerconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package controllerconfig

import (
"strconv"

"github.com/radius-project/radius/pkg/armrpc/hostoptions"
aztoken "github.com/radius-project/radius/pkg/azure/tokencredentials"
"github.com/radius-project/radius/pkg/kubeutil"
Expand Down Expand Up @@ -69,11 +71,29 @@ func New(options hostoptions.HostOptions) (*RecipeControllerConfig, error) {
return nil, err
}

bicepDeleteRetryCount, err := strconv.Atoi(options.Config.Bicep.DeleteRetryCount)
if err != nil {
return nil, err
}

bicepDeleteRetryDeleteSeconds, err := strconv.Atoi(options.Config.Bicep.DeleteRetryDelaySeconds)
if err != nil {
return nil, err
}

cfg.ConfigLoader = configloader.NewEnvironmentLoader(clientOptions)
cfg.Engine = engine.NewEngine(engine.Options{
ConfigurationLoader: cfg.ConfigLoader,
Drivers: map[string]driver.Driver{
recipes.TemplateKindBicep: driver.NewBicepDriver(clientOptions, cfg.DeploymentEngineClient, cfg.ResourceClient),
recipes.TemplateKindBicep: driver.NewBicepDriver(
clientOptions,
cfg.DeploymentEngineClient,
cfg.ResourceClient,
driver.BicepOptions{
DeleteRetryCount: bicepDeleteRetryCount,
DeleteRetryDelaySeconds: bicepDeleteRetryDeleteSeconds,
},
),
recipes.TemplateKindTerraform: driver.NewTerraformDriver(options.UCPConnection, provider.NewSecretProvider(options.Config.SecretProvider),
driver.TerraformOptions{
Path: options.Config.Terraform.Path,
Expand Down
Loading

0 comments on commit b9abe71

Please sign in to comment.