Explorar o código

support exact apply (#4267)

d-g-town %!s(int64=2) %!d(string=hai) anos
pai
achega
f79d81bff8

+ 2 - 0
api/client/porter_app.go

@@ -298,6 +298,7 @@ type UpdateAppInput struct {
 	Base64PorterYAML   string
 	IsEnvOverride      bool
 	WithPredeploy      bool
+	Exact              bool
 }
 
 // UpdateApp updates a porter app
@@ -318,6 +319,7 @@ func (c *Client) UpdateApp(
 		Base64PorterYAML:   inp.Base64PorterYAML,
 		IsEnvOverride:      inp.IsEnvOverride,
 		WithPredeploy:      inp.WithPredeploy,
+		Exact:              inp.Exact,
 	}
 
 	err := c.postRequest(

+ 3 - 0
api/server/handlers/porter_app/update_app.go

@@ -71,6 +71,8 @@ type UpdateAppRequest struct {
 	IsEnvOverride bool `json:"is_env_override"`
 	// WithPredeploy is a flag to indicate whether to run the predeploy job
 	WithPredeploy bool `json:"with_predeploy"`
+	// Exact is a flag to indicate whether to apply the update exactly as specified in the request (default is to merge with existing app)
+	Exact bool `json:"exact"`
 }
 
 // UpdateAppResponse is the response object for the POST /apps/update endpoint
@@ -263,6 +265,7 @@ func (c *UpdateAppHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 		Addons:              addons,
 		AddonOverrides:      addonOverrides,
 		IsPredeployEligible: request.WithPredeploy,
+		Exact:               request.Exact,
 	})
 
 	ccpResp, err := c.Config().ClusterControlPlaneClient.UpdateApp(ctx, updateReq)

+ 3 - 0
cli/cmd/commands/apply.go

@@ -46,6 +46,7 @@ var (
 	// pullImageBeforeBuild is a flag that determines whether to pull the docker image from a repo before building
 	pullImageBeforeBuild bool
 	predeploy            bool
+	exact                bool
 )
 
 func registerCommand_Apply(cliConf config.CLIConfig) *cobra.Command {
@@ -114,6 +115,7 @@ applying a configuration:
 	applyCmd.PersistentFlags().BoolVar(&pullImageBeforeBuild, "pull-before-build", false, "attempt to pull image from registry before building")
 	applyCmd.PersistentFlags().StringVar(&imageTagOverride, "tag", "", "set the image tag used for the application (overrides field in yaml)")
 	applyCmd.PersistentFlags().BoolVar(&predeploy, "predeploy", false, "run predeploy job before deploying the application")
+	applyCmd.PersistentFlags().BoolVar(&exact, "exact", false, "apply the exact configuration as specified in the porter.yaml file (default is to merge with existing configuration)")
 	applyCmd.PersistentFlags().BoolVarP(
 		&appWait,
 		"wait",
@@ -159,6 +161,7 @@ func apply(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client ap
 			WaitForSuccessfulDeployment: appWait,
 			PullImageBeforeBuild:        pullImageBeforeBuild,
 			WithPredeploy:               predeploy,
+			Exact:                       exact,
 		}
 		err := v2.Apply(ctx, inp)
 		if err != nil {

+ 3 - 0
cli/cmd/v2/apply.go

@@ -44,6 +44,8 @@ type ApplyInput struct {
 	PullImageBeforeBuild bool
 	// WithPredeploy is true when Apply should run the predeploy step
 	WithPredeploy bool
+	// Exact is true when Apply should use the exact app config provided by the user
+	Exact bool
 }
 
 // Apply implements the functionality of the `porter apply` command for validate apply v2 projects
@@ -121,6 +123,7 @@ func Apply(ctx context.Context, inp ApplyInput) error {
 		CommitSHA:          commitSHA,
 		Base64PorterYAML:   b64YAML,
 		WithPredeploy:      inp.WithPredeploy,
+		Exact:              inp.Exact,
 	}
 
 	updateResp, err := client.UpdateApp(ctx, updateInput)