-
Notifications
You must be signed in to change notification settings - Fork 23
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
fixed autoscaling bug and updated hpa sample #270
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ metadata: | |
spec: | ||
image: ghcr.io/spinkube/spin-operator/cpu-load-gen:20240311-163328-g1121986 | ||
executor: containerd-shim-spin | ||
enableAutoscaling: true | ||
replicas: 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bacongobbler says:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
resources: | ||
limits: | ||
cpu: 500m | ||
|
@@ -20,8 +20,8 @@ metadata: | |
name: spinapp-autoscaler | ||
spec: | ||
scaleTargetRef: | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
apiVersion: core.spinoperator.dev/v1alpha1 | ||
kind: SpinApp | ||
name: hpa-spinapp | ||
minReplicas: 1 | ||
maxReplicas: 10 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ import ( | |
"fmt" | ||
"hash/adler32" | ||
"maps" | ||
"strings" | ||
|
||
"github.com/pelletier/go-toml/v2" | ||
appsv1 "k8s.io/api/apps/v1" | ||
|
@@ -187,6 +188,8 @@ func (r *SpinAppReconciler) updateStatus(ctx context.Context, app *spinv1alpha1. | |
Reason: "DeploymentNotFound", | ||
Message: "Deployment not found", | ||
}) | ||
|
||
app.Status.Selector = "" | ||
app.Status.ReadyReplicas = 0 | ||
} else { | ||
deploymentConditions := deployment.Status.Conditions | ||
|
@@ -212,6 +215,13 @@ func (r *SpinAppReconciler) updateStatus(ctx context.Context, app *spinv1alpha1. | |
}) | ||
} | ||
} | ||
|
||
var selectorStringArray []string | ||
for key, value := range deployment.Spec.Selector.MatchLabels { | ||
selectorStringArray = append(selectorStringArray, key+"="+value) | ||
} | ||
|
||
app.Status.Selector = strings.Join(selectorStringArray, ",") | ||
app.Status.ReadyReplicas = deployment.Status.ReadyReplicas | ||
} | ||
|
||
|
@@ -381,14 +391,7 @@ func (r *SpinAppReconciler) deleteDeployment(ctx context.Context, app *spinv1alp | |
// constructDeployment builds an appsv1.Deployment based on the configuration of a SpinApp. | ||
func constructDeployment(ctx context.Context, app *spinv1alpha1.SpinApp, config *spinv1alpha1.ExecutorDeploymentConfig, | ||
generatedRuntimeConfigSecretName, caSecretName string, scheme *runtime.Scheme) (*appsv1.Deployment, error) { | ||
// TODO: Once we land admission webhooks write some validation to make | ||
// replicas and enableAutoscaling mutually exclusive. | ||
var replicas *int32 | ||
if app.Spec.EnableAutoscaling { | ||
replicas = nil | ||
} else { | ||
replicas = ptr(app.Spec.Replicas) | ||
} | ||
replicas := app.Spec.Replicas | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bacongobbler says:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
volumes, volumeMounts, err := ConstructVolumeMountsForApp(ctx, app, generatedRuntimeConfigSecretName, caSecretName) | ||
if err != nil { | ||
|
@@ -444,7 +447,7 @@ func constructDeployment(ctx context.Context, app *spinv1alpha1.SpinApp, config | |
Annotations: annotations, | ||
}, | ||
Spec: appsv1.DeploymentSpec{ | ||
Replicas: replicas, | ||
Replicas: &replicas, | ||
Selector: &metav1.LabelSelector{ | ||
MatchLabels: readyLabels, | ||
}, | ||
|
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.
@endocrimes would we have to make this optional to support runtimes where this selector is meaningless? Or is setting it to the empty string sufficient.