Skip to content

Commit

Permalink
minor changes to api-operatorFlagsMergeStrategy
Browse files Browse the repository at this point in the history
  • Loading branch information
SrinivasAtmakuri committed May 15, 2023
1 parent dd95331 commit 5c22b6c
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions pkg/api/admin/operatorflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ import (

type operatorFlagsMergeStrategyStruct struct {
OperatorFlagsMergeStrategy string
Oc api.OpenShiftCluster
Cluster *api.OpenShiftCluster
}

const operatorFlagsMergeStrategyDefault string = "merge"
const (
operatorFlagsMergeStrategyDefault string = "merge"
operatorFlagsMergeStrategyMerge string = "merge"
operatorFlagsMergeStrategyReset string = "reset"
)

// When a cluster is edited via the PATCH Cluster Geneva Action (aka an Admin Update)
// the flags given are treated according to the provided Update Strategy,
Expand All @@ -27,25 +31,30 @@ const operatorFlagsMergeStrategyDefault string = "merge"
func OperatorFlagsMergeStrategy(oc *api.OpenShiftCluster, body []byte) error {
payload := operatorFlagsMergeStrategyStruct{
OperatorFlagsMergeStrategy: operatorFlagsMergeStrategyDefault,
Oc: api.OpenShiftCluster{},
Cluster: &api.OpenShiftCluster{},
}

err := json.Unmarshal(body, &payload)
if err != nil {
return api.NewCloudError(http.StatusBadRequest, api.CloudErrorCodeInvalidRequestContent, "", "The request content was invalid and could not be deserialized: %q.", err)
}

// return if payload is empty
if properties := &payload.Cluster.Properties; payload.Cluster == nil || properties == nil || payload.Cluster.Properties.OperatorFlags == nil {
return nil
}
// return error if OperatorFlagsMergeStrategy is not merge or reset, default is merge
if payload.OperatorFlagsMergeStrategy != "merge" && payload.OperatorFlagsMergeStrategy != "reset" {
if payload.OperatorFlagsMergeStrategy != operatorFlagsMergeStrategyMerge &&
payload.OperatorFlagsMergeStrategy != operatorFlagsMergeStrategyReset {
return api.NewCloudError(http.StatusBadRequest, api.CloudErrorCodeInvalidParameter, "", "invalid operatorFlagsMergeStrategy '%s', can only be 'merge' or 'reset'", payload.OperatorFlagsMergeStrategy)
}
// return nil, if OperatorFlagsMergeStrategy is merge and payload has not operatorFlags
// return operatorFlags of payload, if OperatorFlagsMergeStrategy is merge and payload has operatorFlags
// return defaultOperatorFlags, if OperatorFlagsMergeStrategy is reset and payload has not operatorFlags
// return defaultOperatorFlags + operatorFlags of payload, if OperatorFlagsMergeStrategy is reset and payload has operatorFlags
if payload.OperatorFlagsMergeStrategy == "reset" {
if payload.OperatorFlagsMergeStrategy == operatorFlagsMergeStrategyReset {
oc.Properties.OperatorFlags = api.DefaultOperatorFlags()
for operatorflag, value := range payload.Oc.Properties.OperatorFlags {
for operatorflag, value := range payload.Cluster.Properties.OperatorFlags {
oc.Properties.OperatorFlags[operatorflag] = value
}
}
Expand Down

0 comments on commit 5c22b6c

Please sign in to comment.