/
pa_types.go
145 lines (115 loc) · 5.64 KB
/
pa_types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
Copyright 2018 The Knative Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package v1alpha1
import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
net "knative.dev/networking/pkg/apis/networking"
"knative.dev/pkg/apis"
duckv1 "knative.dev/pkg/apis/duck/v1"
"knative.dev/pkg/kmeta"
)
// +genclient
// +genreconciler:class=autoscaling.knative.dev/class
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// PodAutoscaler is a Knative abstraction that encapsulates the interface by which Knative
// components instantiate autoscalers. This definition is an abstraction that may be backed
// by multiple definitions. For more information, see the Knative Pluggability presentation:
// https://docs.google.com/presentation/d/10KWynvAJYuOEWy69VBa6bHJVCqIsz1TNdEKosNvcpPY/edit
type PodAutoscaler struct {
metav1.TypeMeta `json:",inline"`
// +optional
metav1.ObjectMeta `json:"metadata,omitempty"`
// Spec holds the desired state of the PodAutoscaler (from the client).
// +optional
Spec PodAutoscalerSpec `json:"spec,omitempty"`
// Status communicates the observed state of the PodAutoscaler (from the controller).
// +optional
Status PodAutoscalerStatus `json:"status,omitempty"`
}
// Verify that PodAutoscaler adheres to the appropriate interfaces.
var (
// Check that PodAutoscaler can be validated and can be defaulted.
_ apis.Validatable = (*PodAutoscaler)(nil)
_ apis.Defaultable = (*PodAutoscaler)(nil)
// Check that we can create OwnerReferences to a PodAutoscaler.
_ kmeta.OwnerRefable = (*PodAutoscaler)(nil)
// Check that the type conforms to the duck Knative Resource shape.
_ duckv1.KRShaped = (*PodAutoscaler)(nil)
)
// ReachabilityType is the enumeration type for the different states of reachability
// to the `ScaleTarget` of a `PodAutoscaler`
type ReachabilityType string
const (
// ReachabilityUnknown means the reachability of the `ScaleTarget` is unknown.
// Used when the reachability cannot be determined, eg. during activation.
ReachabilityUnknown ReachabilityType = ""
// ReachabilityReachable means the `ScaleTarget` is reachable, ie. it has an active route.
ReachabilityReachable ReachabilityType = "Reachable"
// ReachabilityUnreachable means the `ScaleTarget` is not reachable, ie. it does not have an active route.
ReachabilityUnreachable ReachabilityType = "Unreachable"
)
// PodAutoscalerSpec holds the desired state of the PodAutoscaler (from the client).
type PodAutoscalerSpec struct {
// ContainerConcurrency specifies the maximum allowed
// in-flight (concurrent) requests per container of the Revision.
// Defaults to `0` which means unlimited concurrency.
// +optional
ContainerConcurrency int64 `json:"containerConcurrency,omitempty"`
// ScaleTargetRef defines the /scale-able resource that this PodAutoscaler
// is responsible for quickly right-sizing.
ScaleTargetRef corev1.ObjectReference `json:"scaleTargetRef"`
// Reachability specifies whether or not the `ScaleTargetRef` can be reached (ie. has a route).
// Defaults to `ReachabilityUnknown`
// +optional
Reachability ReachabilityType `json:"reachability,omitempty"`
// The application-layer protocol. Matches `ProtocolType` inferred from the revision spec.
ProtocolType net.ProtocolType `json:"protocolType"`
}
const (
// PodAutoscalerConditionReady is set when the revision is starting to materialize
// runtime resources, and becomes true when those resources are ready.
PodAutoscalerConditionReady = apis.ConditionReady
// PodAutoscalerConditionScaleTargetInitialized is set when the PodAutoscaler's
// ScaleTargetRef was ready to serve traffic once.
PodAutoscalerConditionScaleTargetInitialized apis.ConditionType = "ScaleTargetInitialized"
// PodAutoscalerConditionActive is set when the PodAutoscaler's ScaleTargetRef is receiving traffic.
PodAutoscalerConditionActive apis.ConditionType = "Active"
// PodAutoscalerConditionSKSReady is set when SKS is ready.
PodAutoscalerConditionSKSReady = "SKSReady"
)
// PodAutoscalerStatus communicates the observed state of the PodAutoscaler (from the controller).
type PodAutoscalerStatus struct {
duckv1.Status `json:",inline"`
// ServiceName is the K8s Service name that serves the revision, scaled by this PA.
// The service is created and owned by the ServerlessService object owned by this PA.
ServiceName string `json:"serviceName"`
// MetricsServiceName is the K8s Service name that provides revision metrics.
// The service is managed by the PA object.
MetricsServiceName string `json:"metricsServiceName"`
// DesiredScale shows the current desired number of replicas for the revision.
DesiredScale *int32 `json:"desiredScale,omitempty"`
// ActualScale shows the actual number of replicas for the revision.
ActualScale *int32 `json:"actualScale,omitempty"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// PodAutoscalerList is a list of PodAutoscaler resources
type PodAutoscalerList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
Items []PodAutoscaler `json:"items"`
}
// GetStatus retrieves the status of the PodAutoscaler. Implements the KRShaped interface.
func (pa *PodAutoscaler) GetStatus() *duckv1.Status {
return &pa.Status.Status
}