-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[release 1.12] Fix bug with user-defined labels in priorityClass (#3246)
HCO already supports user-defined labels in priorityClass, but if another change is done to the priorityClass, either a change in a required label, or a change in the spec fields, the user-defined labels are deleted. This is also happens if the other modofication is done in different request. This PR fixes this issue, and makes sure that user-defined labels are stay in place on update of the priorityClass. As part of the fix, HCO now does not remove and re-create the priorityClass, if only label were changed, but updates it. As result, the update_priority_class was removed as it is not relevant anymore. Signed-off-by: Nahshon Unna-Tsameret <[email protected]>
- Loading branch information
Showing
11 changed files
with
183 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package operands | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
hcov1beta1 "github.com/kubevirt/hyperconverged-cluster-operator/api/v1beta1" | ||
"github.com/kubevirt/hyperconverged-cluster-operator/pkg/patch" | ||
hcoutil "github.com/kubevirt/hyperconverged-cluster-operator/pkg/util" | ||
) | ||
|
||
func getLabels(hc *hcov1beta1.HyperConverged, component hcoutil.AppComponent) map[string]string { | ||
hcoName := hcov1beta1.HyperConvergedName | ||
|
||
if hc.Name != "" { | ||
hcoName = hc.Name | ||
} | ||
|
||
return hcoutil.GetLabels(hcoName, component) | ||
} | ||
|
||
func getLabelPatch(dest, src map[string]string) ([]byte, error) { | ||
const labelPath = "/metadata/labels/" | ||
var patches []patch.JSONPatchAction | ||
|
||
for k, v := range src { | ||
op := "replace" | ||
lbl, ok := dest[k] | ||
|
||
if !ok { | ||
op = "add" | ||
} else if lbl == v { | ||
continue | ||
} | ||
|
||
patches = append(patches, patch.JSONPatchAction{ | ||
Op: op, | ||
Path: labelPath + patch.EscapeJSONPointer(k), | ||
Value: v, | ||
}) | ||
} | ||
|
||
return json.Marshal(patches) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -948,6 +948,7 @@ rules: | |
- watch | ||
- create | ||
- delete | ||
- patch | ||
- apiGroups: | ||
- admissionregistration.k8s.io | ||
resources: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -432,6 +432,7 @@ spec: | |
- watch | ||
- create | ||
- delete | ||
- patch | ||
- apiGroups: | ||
- admissionregistration.k8s.io | ||
resources: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package patch | ||
|
||
import "strings" | ||
|
||
type JSONPatchAction struct { | ||
Op string `json:"op"` | ||
Path string `json:"path"` | ||
Value interface{} `json:"value,omitempty"` | ||
} | ||
|
||
func EscapeJSONPointer(ptr string) string { | ||
s := strings.ReplaceAll(ptr, "~", "~0") | ||
return strings.ReplaceAll(s, "/", "~1") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,8 @@ import ( | |
tests "github.com/kubevirt/hyperconverged-cluster-operator/tests/func-tests" | ||
) | ||
|
||
const priorityClassName = "kubevirt-cluster-critical" | ||
|
||
var _ = Describe("[rfe_id:5672][crit:medium][vendor:[email protected]][level:system]Dependency objects", func() { | ||
flag.Parse() | ||
|
||
|
Oops, something went wrong.