Explorar o código

Improve clarity around SourceConfigID

jnfrati %!s(int64=3) %!d(string=hai) anos
pai
achega
db1d386192

+ 3 - 3
api/server/handlers/stack/create.go

@@ -269,10 +269,10 @@ func getSourceConfigModels(sourceConfigs []*types.CreateStackSourceConfigRequest
 			}
 
 			// If the source config had a source config ID then we need to copy it over
-			if len(sourceConfig.SourceConfigID) != 0 {
-				newSourceConfig.SourceConfigID = sourceConfig.SourceConfigID
+			if sourceConfig.StableSourceConfigID != "" {
+				newSourceConfig.StableSourceConfigID = sourceConfig.StableSourceConfigID
 			} else {
-				newSourceConfig.SourceConfigID = string(uid)
+				newSourceConfig.StableSourceConfigID = string(uid)
 			}
 
 			res = append(res, *newSourceConfig)

+ 2 - 2
api/types/stacks.go

@@ -227,7 +227,7 @@ type StackSourceConfig struct {
 	StackSourceConfigBuild *StackSourceConfigBuild `json:"build,omitempty"`
 
 	// Unique ID to identify between revisions
-	SourceConfigID string `json:"source_config_id"`
+	StableSourceConfigID string `json:"source_config_id"`
 }
 
 // swagger:model
@@ -261,7 +261,7 @@ type CreateStackSourceConfigRequest struct {
 	// required: true
 	ImageTag string `json:"image_tag" form:"required"`
 
-	SourceConfigID string `json:"source_config_id,omitempty"`
+	StableSourceConfigID string `json:"source_config_id,omitempty"`
 
 	// If this field is empty, the resource is deployed directly from the image repo uri
 	StackSourceConfigBuild *StackSourceConfigBuild `json:"build,omitempty"`

+ 12 - 10
internal/models/stack.go

@@ -160,7 +160,9 @@ func (s StackResource) ToStackResource(stackID string, stackRevisionID uint, sou
 type StackSourceConfig struct {
 	gorm.Model
 
-	SourceConfigID string
+	// A unique identifier for this source config, this will allow us identify a same source config
+	// across multiple revisions and updates. This is not the same as the UID or ID which are updated over revisions.
+	StableSourceConfigID string
 
 	StackRevisionID uint
 
@@ -177,15 +179,15 @@ type StackSourceConfig struct {
 
 func (s StackSourceConfig) ToStackSourceConfigType(stackID string, stackRevisionID uint) *types.StackSourceConfig {
 	return &types.StackSourceConfig{
-		CreatedAt:       s.CreatedAt,
-		UpdatedAt:       s.UpdatedAt,
-		StackID:         stackID,
-		StackRevisionID: stackRevisionID,
-		Name:            s.Name,
-		ID:              s.UID,
-		ImageRepoURI:    s.ImageRepoURI,
-		ImageTag:        s.ImageTag,
-		SourceConfigID:  s.SourceConfigID,
+		CreatedAt:            s.CreatedAt,
+		UpdatedAt:            s.UpdatedAt,
+		StackID:              stackID,
+		StackRevisionID:      stackRevisionID,
+		Name:                 s.Name,
+		ID:                   s.UID,
+		ImageRepoURI:         s.ImageRepoURI,
+		ImageTag:             s.ImageTag,
+		StableSourceConfigID: s.StableSourceConfigID,
 	}
 }
 

+ 1 - 2
internal/stacks/helpers.go

@@ -52,8 +52,7 @@ func CloneAppResources(
 			if prevSourceConfig.UID == appResource.StackSourceConfigUID {
 				// find the corresponding new source config
 				for _, newSourceConfig := range newSourceConfigs {
-					fmt.Println(newSourceConfig.SourceConfigID, prevSourceConfig.SourceConfigID)
-					if newSourceConfig.SourceConfigID == prevSourceConfig.SourceConfigID {
+					if newSourceConfig.StableSourceConfigID == prevSourceConfig.StableSourceConfigID {
 						linkedSourceConfigUID = newSourceConfig.UID
 					}
 				}