-
Notifications
You must be signed in to change notification settings - Fork 2
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
Enable replicas override #1178
Enable replicas override #1178
Conversation
pkg/apis/kube/kube.go
Outdated
@@ -53,7 +54,8 @@ const ( | |||
RadixCommitLabel = "radix-commit" | |||
RadixImageTagLabel = "radix-image-tag" | |||
RadixJobTypeLabel = "radix-job-type" | |||
RadixJobTypeJob = "job" // Outer job | |||
RadixJobTypeJob = "job" // Outer job | |||
RadixJobTypeAuxJobSleep = "job-sleep" // Outer job |
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.
What is this label for and why is it called "Sleep"?
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.
fixed
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.
Renamed to job-manager-auxiliary
if override := deployComponent.GetReplicasOverride(); override != nil { | ||
componentReplicas = int32(*override) | ||
} | ||
|
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.
Wouldn't be this method actually this way (and the name of the method is probably not longer consistent, as it participates in garbage-collect for PodDisruption):
func getDesiredComponentReplicas(deployComponent v1.RadixCommonDeployComponent) *int32 {
if override := deployComponent.GetReplicasOverride(); override != nil {
return pointers.Ptr(int32(*override))
}
componentReplicas := int32(DefaultReplicas)
if replicas := deployComponent.GetReplicas(); replicas != nil {
componentReplicas = int32(*replicas)
}
if hs := deployComponent.GetHorizontalScaling(); hs != nil {
if hs.MinReplicas != nil && *hs.MinReplicas > componentReplicas {
componentReplicas = *hs.MinReplicas
}
if hs.MaxReplicas < componentReplicas {
componentReplicas = hs.MaxReplicas
}
}
return pointers.Ptr(componentReplicas)
}
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.
fixed:
func getDeployComponentReplicas(deployComponent v1.RadixCommonDeployComponent) int32 {
if override := deployComponent.GetReplicasOverride(); override != nil {
return int32(*override)
}
componentReplicas := DefaultReplicas
if replicas := deployComponent.GetReplicas(); replicas != nil {
componentReplicas = int32(*replicas)
}
if hs := deployComponent.GetHorizontalScaling(); hs != nil {
if hs.MinReplicas != nil && *hs.MinReplicas > componentReplicas {
return *hs.MinReplicas
}
if hs.MaxReplicas < componentReplicas {
return hs.MaxReplicas
}
}
return componentReplicas
}
@@ -27,6 +28,13 @@ func ForRadixBranch(branch string) map[string]string { | |||
func ForRadixDeploymentName(deploymentName string) map[string]string { | |||
return map[string]string{kube.RadixDeploymentNameAnnotation: deploymentName} | |||
} | |||
func ForKubernetesDeploymentObservedGeneration(rd *radixv1.RadixDeployment) map[string]string { |
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.
Missing comment.
What is this annotation for?
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.
Fixed
pkg/apis/deployment/pdb.go
Outdated
*horizontalScaling.MinReplicas > 1 | ||
} | ||
return replicas > 1 | ||
return *getDesiredComponentReplicas(component) > 1 |
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.
This code is potentially failful - check the nil-able value on nil
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.
fixed
if deployComponent.GetReplicasOverride() != nil { | ||
log.Ctx(ctx).Debug().Msgf("Skip creating ScaledObject %s in namespace %s: manuall override is set", componentName, namespace) | ||
return nil | ||
} |
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.
Move this to the top of the method (optional, but more logical for reading)
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.
fixed
pkg/apis/kube/kube.go
Outdated
@@ -28,6 +28,7 @@ const ( | |||
RadixDeploymentNameAnnotation = "radix-deployment-name" | |||
RadixDeploymentPromotedFromDeploymentAnnotation = "radix.equinor.com/radix-deployment-promoted-from-deployment" | |||
RadixDeploymentPromotedFromEnvironmentAnnotation = "radix.equinor.com/radix-deployment-promoted-from-environment" | |||
RadixDeploymentObservedGeneration = "radix.equinor.com/radix-deployment-observed-generation" |
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.
Suggestion to add a description comment
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.
fixed
Image string `json:"image"` | ||
Ports []ComponentPort `json:"ports"` | ||
Replicas *int `json:"replicas"` | ||
ReplicasOverride *int `json:"replicasOverride"` |
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.
ReplicasOverride *int `json:"replicasOverride"` | |
ReplicasOverride *int `json:"replicasOverride,omitempty"` |
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.
fixed
@@ -76,6 +76,10 @@ func validateDeployComponents(deployment *radixv1.RadixDeployment) []error { | |||
errs = append(errs, err) | |||
} | |||
|
|||
if err := validateReplica(component.ReplicasOverride); err != nil { |
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.
It can be confusing to show the error for the replicas property. Maybe better to have a separate 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.
fixed
if replicas := deployComponent.GetReplicas(); replicas != nil { | ||
componentReplicas = int32(*replicas) | ||
} | ||
|
||
if hs := deployComponent.GetHorizontalScaling(); hs != nil { | ||
if hs.MinReplicas != nil && *hs.MinReplicas > componentReplicas { | ||
componentReplicas = *hs.MinReplicas | ||
return *hs.MinReplicas |
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.
This should not be changed - next if
used its value
componentReplicas = *hs.MinReplicas
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.
Are you sure?
The block
if hs.MinReplicas != nil && *hs.MinReplicas > componentReplicas {
componentReplicas = *hs.MinReplicas
}
Would basically return minReplicas if its above componentReplicas?
} | ||
if hs.MaxReplicas < componentReplicas { | ||
componentReplicas = hs.MaxReplicas | ||
return hs.MaxReplicas |
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.
So maybe this would be also good to have similar componentReplicas = hs.MaxReplicas
- for easy reading
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.
same as the other one:
if hs.MaxReplicas < componentReplicas {
componentReplicas = hs.MaxReplicas
}
Would basically return Max if its less than componentReplicas 🤔
Probably needs to be released together with Radix-API