Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions config/core/200-roles/clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,6 @@ rules:
resources: ["clusterroles"]
verbs: ["delete"]
resourceNames: ["knative-serving-certmanager"]
- apiGroups: ["*"]
resources: ["*/scale"]
verbs: ["patch"]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@dprotaso I assume, this is intentionally wide to allow for scaling different resourecs like mentioned in the issue CloneSet, AppSet. Correct?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah that's the intent

24 changes: 0 additions & 24 deletions docs/serving-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -565,18 +565,6 @@ Kubernetes meta/v1.LabelSelector
<td>
</td>
</tr>
<tr>
<td>
<code>template</code><br/>
<em>
<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.28/#podtemplatespec-v1-core">
Kubernetes core/v1.PodTemplateSpec
</a>
</em>
</td>
<td>
</td>
</tr>
</table>
</td>
</tr>
Expand Down Expand Up @@ -633,18 +621,6 @@ Kubernetes meta/v1.LabelSelector
<td>
</td>
</tr>
<tr>
<td>
<code>template</code><br/>
<em>
<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.28/#podtemplatespec-v1-core">
Kubernetes core/v1.PodTemplateSpec
</a>
</em>
</td>
<td>
</td>
</tr>
</tbody>
</table>
<h3 id="autoscaling.internal.knative.dev/v1alpha1.PodScalableStatus">PodScalableStatus
Expand Down
19 changes: 2 additions & 17 deletions pkg/apis/autoscaling/v1alpha1/podscalable_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package v1alpha1

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"knative.dev/pkg/apis"
Expand All @@ -43,9 +42,8 @@ type PodScalable struct {
// PodScalableSpec is the specification for the desired state of a
// PodScalable (or at least our shared portion).
type PodScalableSpec struct {
Replicas *int32 `json:"replicas,omitempty"`
Selector *metav1.LabelSelector `json:"selector"`
Template corev1.PodTemplateSpec `json:"template"`
Replicas *int32 `json:"replicas,omitempty"`
Selector *metav1.LabelSelector `json:"selector"`
}

// PodScalableStatus is the observed state of a PodScalable (or at
Expand Down Expand Up @@ -80,19 +78,6 @@ func (t *PodScalable) Populate() {
Values: []string{"baz", "blah"},
}},
},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"foo": "bar",
},
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{{
Name: "container-name",
Image: "container-image:latest",
}},
},
},
}
t.Status = PodScalableStatus{
Replicas: 42,
Expand Down
1 change: 0 additions & 1 deletion pkg/apis/autoscaling/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions pkg/reconciler/autoscaling/kpa/kpa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func TestReconcile(t *testing.T) {
minScalePatch := clientgotesting.PatchActionImpl{
ActionImpl: clientgotesting.ActionImpl{Namespace: testNamespace},
Name: deployName,
Patch: []byte(fmt.Sprintf(`[{"op":"replace","path":"/spec/replicas","value":%d}]`, defaultScale)),
Patch: fmt.Appendf(nil, `[{"op":"add","path":"/spec/replicas","value":%d}]`, defaultScale),
}

inactiveKPAMinScale := func(g int32) *autoscalingv1alpha1.PodAutoscaler {
Expand Down Expand Up @@ -1030,7 +1030,7 @@ func TestReconcile(t *testing.T) {
WantPatches: []clientgotesting.PatchActionImpl{{
ActionImpl: clientgotesting.ActionImpl{Namespace: testNamespace},
Name: deployName,
Patch: []byte(fmt.Sprintf(`[{"op":"replace","path":"/spec/replicas","value":%d}]`, 20)),
Patch: fmt.Appendf(nil, `[{"op":"add","path":"/spec/replicas","value":%d}]`, 20),
}},
}, {
Name: "initial scale reached, mark PA as active",
Expand Down Expand Up @@ -1058,7 +1058,7 @@ func TestReconcile(t *testing.T) {
WantPatches: []clientgotesting.PatchActionImpl{{
ActionImpl: clientgotesting.ActionImpl{Namespace: testNamespace},
Name: deployName,
Patch: []byte(fmt.Sprintf(`[{"op":"replace","path":"/spec/replicas","value":%d}]`, 20)),
Patch: fmt.Appendf(nil, `[{"op":"add","path":"/spec/replicas","value":%d}]`, 20),
}},
}, {
Name: "initial scale zero: scale to zero",
Expand Down
25 changes: 12 additions & 13 deletions pkg/reconciler/autoscaling/kpa/scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,10 @@ func (ks *scaler) handleScaleToZero(ctx context.Context, pa *autoscalingv1alpha1
}
}

func (ks *scaler) applyScale(ctx context.Context, pa *autoscalingv1alpha1.PodAutoscaler, desiredScale int32,
func (ks *scaler) applyScale(
ctx context.Context,
pa *autoscalingv1alpha1.PodAutoscaler,
desiredScale int32,
ps *autoscalingv1alpha1.PodScalable,
) error {
logger := logging.FromContext(ctx)
Expand All @@ -308,19 +311,15 @@ func (ks *scaler) applyScale(ctx context.Context, pa *autoscalingv1alpha1.PodAut
return err
}

psNew := ps.DeepCopy()
psNew.Spec.Replicas = &desiredScale
patch, err := duck.CreatePatch(ps, psNew)
if err != nil {
return err
}
patchBytes, err := patch.MarshalJSON()
if err != nil {
return err
}
patch := fmt.Sprintf(`[{"op":"add","path":"/spec/replicas","value":%d}]`, desiredScale)

_, err = ks.dynamicClient.Resource(*gvr).Namespace(pa.Namespace).Patch(ctx, ps.Name, types.JSONPatchType,
patchBytes, metav1.PatchOptions{})
_, err = ks.dynamicClient.Resource(*gvr).Namespace(pa.Namespace).Patch(
ctx,
ps.Name,
types.JSONPatchType,
[]byte(patch),
metav1.PatchOptions{},
"scale")
if err != nil {
return fmt.Errorf("failed to apply scale %d to scale target %s: %w", desiredScale, name, err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/autoscaling/kpa/scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ func checkReplicas(t *testing.T, dynamicClient *fakedynamic.FakeDynamicClient, d
if patch.GetName() != deployment.Name {
continue
}
want := fmt.Sprintf(`[{"op":"replace","path":"/spec/replicas","value":%d}]`, expectedScale)
want := fmt.Sprintf(`[{"op":"add","path":"/spec/replicas","value":%d}]`, expectedScale)
if got := string(patch.GetPatch()); got != want {
t.Errorf("Patch = %s, wanted %s", got, want)
}
Expand Down
Loading