From 2756cad4b5563da0d446f4c09100e8604db8c675 Mon Sep 17 00:00:00 2001 From: sk593 Date: Mon, 11 Sep 2023 14:01:07 -0700 Subject: [PATCH] addressing comments --- pkg/corerp/datamodel/extender.go | 5 ----- pkg/daprrp/datamodel/daprpubsubbroker.go | 5 ----- pkg/daprrp/datamodel/daprsecretstore.go | 5 ----- pkg/daprrp/datamodel/daprstatestore.go | 5 ----- pkg/datastoresrp/datamodel/mongodatabase.go | 5 ----- pkg/datastoresrp/datamodel/rediscache.go | 5 ----- pkg/datastoresrp/datamodel/sqldatabase.go | 5 ----- pkg/messagingrp/datamodel/rabbitmq.go | 5 ----- .../backend/controller/createorupdateresource.go | 4 ++-- .../backend/controller/createorupdateresource_test.go | 5 ----- pkg/portableresources/datamodel/recipes.go | 2 -- pkg/recipes/configloader/environment.go | 6 +++--- pkg/recipes/configloader/environment_test.go | 2 +- pkg/recipes/errorcodes.go | 3 +++ test/functional/shared/resources/recipe_test.go | 2 +- 15 files changed, 10 insertions(+), 54 deletions(-) diff --git a/pkg/corerp/datamodel/extender.go b/pkg/corerp/datamodel/extender.go index 6502ff8b6ae..b8e15920154 100644 --- a/pkg/corerp/datamodel/extender.go +++ b/pkg/corerp/datamodel/extender.go @@ -66,11 +66,6 @@ func (r *Extender) Recipe() *portableresources.ResourceRecipe { return &r.Properties.ResourceRecipe } -// SetDeploymentStatus updates the deployment status of the Extender resource. -func (r *Extender) SetDeploymentStatus(status portableresources.RecipeDeploymentStatus) { - r.Recipe().DeploymentStatus = status -} - // ExtenderProperties represents the properties of Extender resource. type ExtenderProperties struct { rpv1.BasicResourceProperties diff --git a/pkg/daprrp/datamodel/daprpubsubbroker.go b/pkg/daprrp/datamodel/daprpubsubbroker.go index 47d27ff2fef..dfd17bba769 100644 --- a/pkg/daprrp/datamodel/daprpubsubbroker.go +++ b/pkg/daprrp/datamodel/daprpubsubbroker.go @@ -62,11 +62,6 @@ func (r *DaprPubSubBroker) Recipe() *portableresources.ResourceRecipe { return &r.Properties.Recipe } -// SetDeploymentStatus updates the deployment status of the Dapr Pub/Sub Broker resource. -func (r *DaprPubSubBroker) SetDeploymentStatus(status portableresources.RecipeDeploymentStatus) { - r.Recipe().DeploymentStatus = status -} - // DaprPubSubBrokerProperties represents the properties of Dapr PubSubBroker resource. type DaprPubSubBrokerProperties struct { rpv1.BasicResourceProperties diff --git a/pkg/daprrp/datamodel/daprsecretstore.go b/pkg/daprrp/datamodel/daprsecretstore.go index 69267a7a97b..b0b92777c5f 100644 --- a/pkg/daprrp/datamodel/daprsecretstore.go +++ b/pkg/daprrp/datamodel/daprsecretstore.go @@ -54,11 +54,6 @@ func (r *DaprSecretStore) ResourceTypeName() string { return portableresources.DaprSecretStoresResourceType } -// SetDeploymentStatus updates the deployment status of the Dapr SecretStore resource. -func (r *DaprSecretStore) SetDeploymentStatus(status portableresources.RecipeDeploymentStatus) { - r.Recipe().DeploymentStatus = status -} - // DaprSecretStoreProperties represents the properties of DaprSecretStore resource. type DaprSecretStoreProperties struct { rpv1.BasicResourceProperties diff --git a/pkg/daprrp/datamodel/daprstatestore.go b/pkg/daprrp/datamodel/daprstatestore.go index 6dc09e0ba9c..97d4737c19e 100644 --- a/pkg/daprrp/datamodel/daprstatestore.go +++ b/pkg/daprrp/datamodel/daprstatestore.go @@ -62,11 +62,6 @@ func (r *DaprStateStore) Recipe() *portableresources.ResourceRecipe { return &r.Properties.Recipe } -// SetDeploymentStatus updates the deployment status of the DaprStateStore resource. -func (r *DaprStateStore) SetDeploymentStatus(status portableresources.RecipeDeploymentStatus) { - r.Recipe().DeploymentStatus = status -} - // DaprStateStoreProperties represents the properties of DaprStateStore resource. type DaprStateStoreProperties struct { rpv1.BasicResourceProperties diff --git a/pkg/datastoresrp/datamodel/mongodatabase.go b/pkg/datastoresrp/datamodel/mongodatabase.go index af3c5c458ff..21052cfef98 100644 --- a/pkg/datastoresrp/datamodel/mongodatabase.go +++ b/pkg/datastoresrp/datamodel/mongodatabase.go @@ -124,11 +124,6 @@ func (r *MongoDatabase) Recipe() *portableresources.ResourceRecipe { return &r.Properties.Recipe } -// SetDeploymentStatus updates the deployment status of the Mongo database resource. -func (r *MongoDatabase) SetDeploymentStatus(status portableresources.RecipeDeploymentStatus) { - r.Recipe().DeploymentStatus = status -} - // ResourceTypeName returns the resource type for Mongo database resource. func (mongoSecrets *MongoDatabaseSecrets) ResourceTypeName() string { return portableresources.MongoDatabasesResourceType diff --git a/pkg/datastoresrp/datamodel/rediscache.go b/pkg/datastoresrp/datamodel/rediscache.go index 43279e30701..660db2ce19a 100644 --- a/pkg/datastoresrp/datamodel/rediscache.go +++ b/pkg/datastoresrp/datamodel/rediscache.go @@ -100,11 +100,6 @@ func (r *RedisCache) VerifyInputs() error { return nil } -// SetDeploymentStatus updates the deployment status of the Redis cache resource. -func (r *RedisCache) SetDeploymentStatus(status portableresources.RecipeDeploymentStatus) { - r.Recipe().DeploymentStatus = status -} - type RedisCacheProperties struct { rpv1.BasicResourceProperties // The host name of the target Redis cache diff --git a/pkg/datastoresrp/datamodel/sqldatabase.go b/pkg/datastoresrp/datamodel/sqldatabase.go index 0631ddab108..8483d829602 100644 --- a/pkg/datastoresrp/datamodel/sqldatabase.go +++ b/pkg/datastoresrp/datamodel/sqldatabase.go @@ -67,11 +67,6 @@ func (r *SqlDatabase) ResourceTypeName() string { return portableresources.SqlDatabasesResourceType } -// SetDeploymentStatus updates the deployment status of the SQL Databse resource. -func (r *SqlDatabase) SetDeploymentStatus(status portableresources.RecipeDeploymentStatus) { - r.Recipe().DeploymentStatus = status -} - // SqlDatabaseProperties represents the properties of SQL database resource. type SqlDatabaseProperties struct { rpv1.BasicResourceProperties diff --git a/pkg/messagingrp/datamodel/rabbitmq.go b/pkg/messagingrp/datamodel/rabbitmq.go index aa77fbf5f90..0cb7812dbc9 100644 --- a/pkg/messagingrp/datamodel/rabbitmq.go +++ b/pkg/messagingrp/datamodel/rabbitmq.go @@ -58,11 +58,6 @@ func (r *RabbitMQQueue) ResourceTypeName() string { return portableresources.RabbitMQQueuesResourceType } -// SetDeploymentStatus updates the deployment status of the RabbitMQ resource. -func (r *RabbitMQQueue) SetDeploymentStatus(status portableresources.RecipeDeploymentStatus) { - r.Recipe().DeploymentStatus = status -} - // RabbitMQQueueProperties represents the properties of RabbitMQQueue response resource. type RabbitMQQueueProperties struct { rpv1.BasicResourceProperties diff --git a/pkg/portableresources/backend/controller/createorupdateresource.go b/pkg/portableresources/backend/controller/createorupdateresource.go index 50d92c5ad07..1d2796285ee 100644 --- a/pkg/portableresources/backend/controller/createorupdateresource.go +++ b/pkg/portableresources/backend/controller/createorupdateresource.go @@ -82,7 +82,7 @@ func (c *CreateOrUpdateResource[P, T]) Run(ctx context.Context, req *ctrl.Reques if err != nil { if recipeError, ok := err.(*recipes.RecipeError); ok { // Set the deployment status to the recipe error code. - recipeDataModel.SetDeploymentStatus(portableresources.RecipeDeploymentStatus(recipeError.DeploymentStatus)) + recipeDataModel.Recipe().DeploymentStatus = portableresources.RecipeDeploymentStatus(recipeError.DeploymentStatus) update := &store.Object{ Metadata: store.Metadata{ ID: req.ResourceID, @@ -111,7 +111,7 @@ func (c *CreateOrUpdateResource[P, T]) Run(ctx context.Context, req *ctrl.Reques return ctrl.Result{}, err } - recipeDataModel.SetDeploymentStatus(portableresources.Success) + recipeDataModel.Recipe().DeploymentStatus = portableresources.Success update := &store.Object{ Metadata: store.Metadata{ ID: req.ResourceID, diff --git a/pkg/portableresources/backend/controller/createorupdateresource_test.go b/pkg/portableresources/backend/controller/createorupdateresource_test.go index 85a70b1ca33..6a6a75498da 100644 --- a/pkg/portableresources/backend/controller/createorupdateresource_test.go +++ b/pkg/portableresources/backend/controller/createorupdateresource_test.go @@ -80,11 +80,6 @@ func (t *TestResource) Recipe() *portableresources.ResourceRecipe { return &t.Properties.Recipe } -// Recipe returns a pointer to the ResourceRecipe stored in the Properties field of the TestResource struct. -func (t *TestResource) SetDeploymentStatus(status portableresources.RecipeDeploymentStatus) { - t.Properties.Recipe.DeploymentStatus = status -} - type TestResourceProperties struct { rpv1.BasicResourceProperties IsProcessed bool `json:"isProcessed"` diff --git a/pkg/portableresources/datamodel/recipes.go b/pkg/portableresources/datamodel/recipes.go index d9af5065e69..a39218fa809 100644 --- a/pkg/portableresources/datamodel/recipes.go +++ b/pkg/portableresources/datamodel/recipes.go @@ -28,6 +28,4 @@ import ( type RecipeDataModel interface { // Recipe provides access to the user-specified recipe configuration. Can return nil. Recipe() *portableresources.ResourceRecipe - // SetDeploymentStatus updates the deployment status of the resource. - SetDeploymentStatus(status portableresources.RecipeDeploymentStatus) } diff --git a/pkg/recipes/configloader/environment.go b/pkg/recipes/configloader/environment.go index dfaee708eb7..0b842680a01 100644 --- a/pkg/recipes/configloader/environment.go +++ b/pkg/recipes/configloader/environment.go @@ -126,19 +126,19 @@ func (e *environmentLoader) LoadRecipe(ctx context.Context, recipe *recipes.Reso func getRecipeDefinition(environment *v20220315privatepreview.EnvironmentResource, recipe *recipes.ResourceMetadata) (*recipes.EnvironmentDefinition, error) { if environment.Properties.Recipes == nil { msg := &recipes.ErrRecipeNotFound{Name: recipe.Name, Environment: recipe.EnvironmentID} - return nil, recipes.NewRecipeError(recipes.RecipeValidationFailed, msg.Error(), portableresources.RecipeSetupError, recipes.GetRecipeErrorDetails(msg)) + return nil, recipes.NewRecipeError(recipes.RecipeNotFoundFailure, msg.Error(), portableresources.RecipeSetupError, recipes.GetRecipeErrorDetails(msg)) } resource, err := resources.ParseResource(recipe.ResourceID) if err != nil { msg := fmt.Errorf("failed to parse resourceID: %q %w", recipe.ResourceID, err) - return nil, recipes.NewRecipeError(recipes.RecipeValidationFailed, msg.Error(), portableresources.RecipeSetupError, recipes.GetRecipeErrorDetails(msg)) + return nil, recipes.NewRecipeError(recipes.RecipeValidationFailed, err.Error(), portableresources.RecipeSetupError, recipes.GetRecipeErrorDetails(msg)) } recipeName := recipe.Name found, ok := environment.Properties.Recipes[resource.Type()][recipeName] if !ok { msg := &recipes.ErrRecipeNotFound{Name: recipe.Name, Environment: recipe.EnvironmentID} - return nil, recipes.NewRecipeError(recipes.RecipeValidationFailed, msg.Error(), portableresources.RecipeSetupError, recipes.GetRecipeErrorDetails(msg)) + return nil, recipes.NewRecipeError(recipes.RecipeNotFoundFailure, msg.Error(), portableresources.RecipeSetupError, recipes.GetRecipeErrorDetails(msg)) } definition := &recipes.EnvironmentDefinition{ diff --git a/pkg/recipes/configloader/environment_test.go b/pkg/recipes/configloader/environment_test.go index 6e0623eefc7..98e5934905a 100644 --- a/pkg/recipes/configloader/environment_test.go +++ b/pkg/recipes/configloader/environment_test.go @@ -249,7 +249,7 @@ func TestGetRecipeDefinition(t *testing.T) { metadata.ResourceID = "invalid-id" _, err := getRecipeDefinition(&envResource, &metadata) require.Error(t, err) - require.Contains(t, err.Error(), "failed to parse resourceID") + require.Contains(t, err.Error(), "'invalid-id' is not a valid resource id") }) t.Run("recipe not found for the resource type", func(t *testing.T) { diff --git a/pkg/recipes/errorcodes.go b/pkg/recipes/errorcodes.go index 19e51739d98..ad904ba2790 100644 --- a/pkg/recipes/errorcodes.go +++ b/pkg/recipes/errorcodes.go @@ -37,4 +37,7 @@ const ( // Used for errors encountered when getting recipe parameters. RecipeGetMetadataFailed = "RecipeGetMetadataFailed" + + // Used for errors when checking the existence of a recipe. + RecipeNotFoundFailure = "RecipeNotFoundFailure" ) diff --git a/test/functional/shared/resources/recipe_test.go b/test/functional/shared/resources/recipe_test.go index cd9936e6e43..28ca5f5eeb8 100644 --- a/test/functional/shared/resources/recipe_test.go +++ b/test/functional/shared/resources/recipe_test.go @@ -41,7 +41,7 @@ func Test_Recipe_NotFound(t *testing.T) { Code: "ResourceDeploymentFailure", Details: []step.DeploymentErrorDetail{ { - Code: recipes.RecipeValidationFailed, + Code: recipes.RecipeNotFoundFailure, MessageContains: "could not find recipe \"not found!\" in environment", }, },