-
Notifications
You must be signed in to change notification settings - Fork 175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support validate policy of opsrequest #8232
base: main
Are you sure you want to change the base?
feat: support validate policy of opsrequest #8232
Conversation
eb5f7c9
to
23483db
Compare
23483db
to
9f847d9
Compare
9f847d9
to
5cdc5d0
Compare
5cdc5d0
to
12c2f78
Compare
12c2f78
to
ae9ee0a
Compare
ae9ee0a
to
3ae1621
Compare
fix the conflicts and make test error |
3ae1621
to
c0c977c
Compare
sorry that i forgot to push newest code. I have already push the newest version. plz check. |
c0c977c
to
8798f3d
Compare
8798f3d
to
531b35d
Compare
531b35d
to
088b7ce
Compare
088b7ce
to
da2b678
Compare
opsRes *OpsResource, | ||
lastCompConfiguration opsv1alpha1.LastComponentConfiguration, | ||
obj ComponentOpsInterface, | ||
) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better with the following function:
func (hs horizontalScalingOpsHandler) validateHorizontalScaling(
opsRes *OpsResource,
lastCompConfiguration opsv1alpha1.LastComponentConfiguration,
horizontalScaling opsv1alpha1.HorizontalScaling,
) error {
if opsRes.OpsRequest.Annotations[constant.IgnoreHscaleValidateAnnoKey] == "true" {
return nil
}
if horizontalScaling.ScaleIn != nil {
if err := hs.validateOnlineInstancesToOffline(lastCompConfiguration,
horizontalScaling.ScaleIn.OnlineInstancesToOffline, opsRes.Cluster.Name, horizontalScaling.ComponentName); err != nil {
return err
}
}
if horizontalScaling.ScaleOut != nil {
if err := hs.validateOfflineInstancesToOnline(lastCompConfiguration,
horizontalScaling.ScaleOut.OfflineInstancesToOnline, horizontalScaling.ComponentName); err != nil {
return err
}
}
return nil
}
func (hs horizontalScalingOpsHandler) validateOnlineInstancesToOffline(
lastCompConfiguration opsv1alpha1.LastComponentConfiguration,
onlineInstancesToOffline []string,
clusterName, componentName string) error {
if len(onlineInstancesToOffline) == 0 {
return nil
}
toOfflineSet := sets.New(onlineInstancesToOffline...)
if len(toOfflineSet) < len(onlineInstancesToOffline) {
return intctrlutil.NewFatalError("instances specified in onlineInstancesToOffline has duplicates")
}
currPodSet, err := intctrlcomp.GenerateAllPodNamesToSet(*lastCompConfiguration.Replicas, lastCompConfiguration.Instances,
lastCompConfiguration.OfflineInstances, clusterName, componentName)
if err != nil {
return err
}
for _, onlineIns := range onlineInstancesToOffline {
if _, ok := currPodSet[onlineIns]; !ok {
return intctrlutil.NewFatalError(fmt.Sprintf(`instance "%s" specified in onlineInstancesToOffline is not onlinee`, onlineIns))
}
}
return nil
}
func (hs horizontalScalingOpsHandler) validateOfflineInstancesToOnline(
lastCompConfiguration opsv1alpha1.LastComponentConfiguration,
offlineInstancesToOnline []string,
componentName string) error {
if len(offlineInstancesToOnline) == 0 {
return nil
}
toOnlineSet := sets.New(offlineInstancesToOnline...)
if len(toOnlineSet) < len(offlineInstancesToOnline) {
return intctrlutil.NewFatalError("instances specified in offlineInstancesToOnline has duplicates")
}
offlineInstanceSet := sets.New(lastCompConfiguration.OfflineInstances...)
for _, offlineIns := range offlineInstancesToOnline {
if _, ok := offlineInstanceSet[offlineIns]; !ok {
return intctrlutil.NewFatalError(fmt.Sprintf(`cannot find the offline instance "%s" in component "%s" for scaleOut operation`, offlineIns, componentName))
}
}
return nil
}
@@ -26,7 +26,6 @@ import ( | |||
"strings" | |||
|
|||
corev1 "k8s.io/api/core/v1" | |||
"k8s.io/apimachinery/pkg/util/intstr" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rebase main branch
} | ||
} | ||
return diff | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove it.
insTplName := appsv1.GetInstanceTemplateName(opsRes.Cluster.Name, horizontalScaling.ComponentName, insName) | ||
onlineInsCountMap[insTplName]++ | ||
} | ||
onlineInsCountMap := opsRes.OpsRequest.CountOfflineOrOnlineInstances(opsRes.Cluster.Name, horizontalScaling.ComponentName, scaleOut.OfflineInstancesToOnline) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert it.
There is a scenario where the original offlineInstances were [pod1, pod3, pod10], and the offlineInstancesToOnline was pod10. However, the current replicas count is 2, which means that pod10 will not actually go online.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or, calculate the real onlineInstances in filterHorizontalScalingSpec
solve #8231