Skip to content
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

Merged
merged 20 commits into from
Sep 11, 2024
Merged

Enable replicas override #1178

merged 20 commits into from
Sep 11, 2024

Conversation

Richard87
Copy link
Contributor

@Richard87 Richard87 commented Aug 23, 2024

Probably needs to be released together with Radix-API

@Richard87 Richard87 self-assigned this Aug 23, 2024
@Richard87 Richard87 requested a review from satr September 3, 2024 09:51
@Richard87 Richard87 marked this pull request as ready for review September 3, 2024 09:55
@@ -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
Copy link
Contributor

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"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link
Contributor Author

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

Comment on lines 373 to 376
if override := deployComponent.GetReplicasOverride(); override != nil {
componentReplicas = int32(*override)
}

Copy link
Contributor

@satr satr Sep 10, 2024

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)
}

Copy link
Contributor Author

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 {
Copy link
Contributor

@satr satr Sep 10, 2024

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

*horizontalScaling.MinReplicas > 1
}
return replicas > 1
return *getDesiredComponentReplicas(component) > 1
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment on lines +27 to +30
if deployComponent.GetReplicasOverride() != nil {
log.Ctx(ctx).Debug().Msgf("Skip creating ScaledObject %s in namespace %s: manuall override is set", componentName, namespace)
return nil
}
Copy link
Contributor

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -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"
Copy link
Contributor

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

Copy link
Contributor Author

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"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ReplicasOverride *int `json:"replicasOverride"`
ReplicasOverride *int `json:"replicasOverride,omitempty"`

Copy link
Contributor Author

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 {
Copy link
Contributor

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

Copy link
Contributor Author

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
Copy link
Contributor

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

Copy link
Contributor Author

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
Copy link
Contributor

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

Copy link
Contributor Author

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 🤔

@Richard87 Richard87 merged commit a7a1e27 into master Sep 11, 2024
7 checks passed
@Richard87 Richard87 deleted the enable-replicas-override branch September 11, 2024 05:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants