-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changes to latency-profile-observer,controller
- use a slice for suppress fns in NewLatencyProfileObserver - add new suppressor fn: NewSuppressConfigUpdateForExtremeProfilesFunc - add checkRejectFn in controller to update status when rejection occurs Signed-off-by: Swarup Ghosh <swghosh@redhat.com>
- Loading branch information
Showing
6 changed files
with
276 additions
and
49 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
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
90 changes: 90 additions & 0 deletions
90
pkg/operator/latencyprofilecontroller/profilerejectionchecker.go
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,90 @@ | ||
package latencyprofilecontroller | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
|
||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
listersv1 "k8s.io/client-go/listers/core/v1" | ||
|
||
configv1 "github.com/openshift/api/config/v1" | ||
nodeobserver "github.com/openshift/library-go/pkg/operator/configobserver/node" | ||
) | ||
|
||
type profileRejectRevisionChecker struct { | ||
configMapLister listersv1.ConfigMapNamespaceLister | ||
profileRejectionScenarios []nodeobserver.LatencyProfileRejectionScenario | ||
latencyConfigs []nodeobserver.LatencyConfigProfileTuple | ||
} | ||
|
||
// NewInstallerProfileRejectionChecker | ||
func NewInstallerProfileRejectionChecker( | ||
configMapLister listersv1.ConfigMapNamespaceLister, | ||
profileRejectionScenarios []nodeobserver.LatencyProfileRejectionScenario, | ||
latencyConfigs []nodeobserver.LatencyConfigProfileTuple, | ||
) CheckProfileRejectionFunc { | ||
|
||
ret := profileRejectRevisionChecker{ | ||
configMapLister: configMapLister, | ||
profileRejectionScenarios: profileRejectionScenarios, | ||
latencyConfigs: latencyConfigs, | ||
} | ||
return ret.checkProfileRejection | ||
} | ||
|
||
func (r *profileRejectRevisionChecker) checkProfileRejection(targetProfile configv1.WorkerLatencyProfileType, revisions []int32) (isRejected bool, rejectMsg string, err error) { | ||
if len(revisions) <= 0 { | ||
return false, "", fmt.Errorf("no revisions found for comparison") | ||
} | ||
highestRevision := revisions[0] | ||
for _, revision := range revisions { | ||
if revision > highestRevision { | ||
highestRevision = revision | ||
} | ||
} | ||
|
||
usedConfigPaths := make([][]string, len(r.latencyConfigs)) | ||
knownProfileConfigs := make(map[configv1.WorkerLatencyProfileType]map[string]interface{}) | ||
|
||
for i, latencyConfig := range r.latencyConfigs { | ||
for profile := range latencyConfig.ProfileConfigValues { | ||
profileValue := latencyConfig.ProfileConfigValues[profile] | ||
|
||
_, ok := knownProfileConfigs[profile] | ||
if !ok { | ||
knownProfileConfigs[profile] = make(map[string]interface{}) | ||
} | ||
err = unstructured.SetNestedStringSlice(knownProfileConfigs[profile], []string{profileValue}, latencyConfig.ConfigPath...) | ||
if err != nil { | ||
return false, "", err | ||
} | ||
} | ||
usedConfigPaths[i] = latencyConfig.ConfigPath | ||
} | ||
|
||
configMap, err := r.configMapLister.Get(fmt.Sprintf("%s-%d", revisionConfigMapName, highestRevision)) | ||
if err != nil { | ||
return false, "", err | ||
} | ||
|
||
currentConfigPruned, err := getPrunedConfigFromConfigMap(configMap, usedConfigPaths) | ||
if err != nil { | ||
return false, "", err | ||
} | ||
|
||
var fromProfile configv1.WorkerLatencyProfileType | ||
for profile := range knownProfileConfigs { | ||
if reflect.DeepEqual(currentConfigPruned, knownProfileConfigs[profile]) { | ||
fromProfile = profile | ||
break | ||
} | ||
} | ||
|
||
for _, rejectionScenario := range r.profileRejectionScenarios { | ||
if fromProfile == rejectionScenario.FromProfile && targetProfile == rejectionScenario.ToProfile { | ||
return true, fmt.Sprintf("rejected update from %q to %q latency profile as extreme profile transition is unsupported", fromProfile, targetProfile), nil | ||
} | ||
} | ||
|
||
return false, "", nil | ||
} |
Oops, something went wrong.