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

Add Knative Traffic management and autoscaling support #640

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
33 changes: 33 additions & 0 deletions api/v1/runtimecomponent_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
networkingv1 "k8s.io/api/networking/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
servingv1 "knative.dev/serving/pkg/apis/serving/v1"
)

// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
Expand Down Expand Up @@ -106,6 +107,9 @@ type RuntimeComponentSpec struct {
// +operator-sdk:csv:customresourcedefinitions:order=17,type=spec,displayName="Monitoring"
Monitoring *RuntimeComponentMonitoring `json:"monitoring,omitempty"`

// +operator-sdk:csv:customresourcedefinitions:order=17,type=spec,displayName="Knative Service"
KnativeService *RuntimeComponentKnativeService `json:"knative,omitempty"`

// An array of environment variables for the application container.
// +listType=map
// +listMapKey=name
Expand Down Expand Up @@ -358,6 +362,17 @@ type RuntimeComponentMonitoring struct {
Endpoints []prometheusv1.Endpoint `json:"endpoints,omitempty"`
}

// Specifies parameters for Knative Service.
type RuntimeComponentKnativeService struct {
// List of traffic targets.
// +operator-sdk:csv:customresourcedefinitions:order=22,type=spec,displayName="Traffic Targets"
TrafficTarget []servingv1.TrafficTarget `json:"traffic,omitempty"`

// Annotations for Autoscaling.
// +operator-sdk:csv:customresourcedefinitions:order=22,type=spec,displayName="Autoscaling Annotations"
AutoscalingAnnotations map[string]string `json:"autoscaling,omitempty"`
}

// Configures the ingress resource.
// +k8s:openapi-gen=true
type RuntimeComponentRoute struct {
Expand Down Expand Up @@ -657,6 +672,14 @@ func (cr *RuntimeComponent) GetMonitoring() common.BaseComponentMonitoring {
return cr.Spec.Monitoring
}

// GetMonitoring returns monitoring settings
func (cr *RuntimeComponent) GetKnativeService() common.BaseComponentKnativeService {
if cr.Spec.KnativeService == nil {
return nil
}
return cr.Spec.KnativeService
}

// GetStatus returns RuntimeComponent status
func (cr *RuntimeComponent) GetStatus() common.BaseComponentStatus {
return &cr.Status
Expand Down Expand Up @@ -873,6 +896,16 @@ func (m *RuntimeComponentMonitoring) GetEndpoints() []prometheusv1.Endpoint {
return m.Endpoints
}

// GetTrafficTarget returns traffic targets for Knative
func (k *RuntimeComponentKnativeService) GetTrafficTarget() []servingv1.TrafficTarget {
return k.TrafficTarget
}

// GetTrafficTarget returns traffic targets for Knative
func (k *RuntimeComponentKnativeService) GetAutoscalingAnnotations() map[string]string {
return k.AutoscalingAnnotations
}

// GetAnnotations returns route annotations
func (r *RuntimeComponentRoute) GetAnnotations() map[string]string {
return r.Annotations
Expand Down
35 changes: 35 additions & 0 deletions api/v1/zz_generated.deepcopy.go

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

60 changes: 60 additions & 0 deletions bundle/manifests/rc.app.stacks_runtimecomponents.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2460,6 +2460,66 @@ spec:
x-kubernetes-list-map-keys:
- name
x-kubernetes-list-type: map
knative:
description: Specifies parameters for Knative Service.
properties:
autoscaling:
additionalProperties:
type: string
description: Annotations for Autoscaling.
type: object
traffic:
description: List of traffic targets.
items:
description: TrafficTarget holds a single entry of the routing
table for a Route.
properties:
configurationName:
description: ConfigurationName of a configuration to whose
latest revision we will send this portion of traffic.
When the "status.latestReadyRevisionName" of the referenced
configuration changes, we will automatically migrate traffic
from the prior "latest ready" revision to the new one. This
field is never set in Route's status, only its spec. This
is mutually exclusive with RevisionName.
type: string
latestRevision:
description: LatestRevision may be optionally provided to
indicate that the latest ready Revision of the Configuration
should be used for this traffic target. When provided
LatestRevision must be true if RevisionName is empty;
it must be false when RevisionName is non-empty.
type: boolean
percent:
description: 'Percent indicates that percentage based routing
should be used and the value indicates the percent of
traffic that is be routed to this Revision or Configuration.
`0` (zero) mean no traffic, `100` means all traffic. When
percentage based routing is being used the follow rules
apply: - the sum of all percent values must equal 100
- when not specified, the implied value for `percent`
is zero for that particular Revision or Configuration'
format: int64
type: integer
revisionName:
description: RevisionName of a specific revision to which
to send this portion of traffic. This is mutually exclusive
with ConfigurationName.
type: string
tag:
description: Tag is optionally used to expose a dedicated
url for referencing this target exclusively.
type: string
url:
description: URL displays the URL for accessing named traffic
targets. URL is displayed in status, and is disallowed
on spec. URL must contain a scheme (e.g. http://) and
a hostname, but may not contain anything else (e.g. basic
auth, url path, etc.)
type: string
type: object
type: array
type: object
manageTLS:
description: Enable management of TLS certificates. Defaults to true.
type: boolean
Expand Down
10 changes: 9 additions & 1 deletion bundle/manifests/runtime-component.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ metadata:
categories: Application Runtime
certified: "true"
containerImage: icr.io/appcafe/runtime-component-operator:daily
createdAt: "2024-05-24T20:56:30Z"
createdAt: "2024-07-09T13:58:29Z"
description: Deploys any runtime component with dynamic and auto-tuning configuration
olm.skipRange: '>=0.8.0 <1.3.2'
operators.openshift.io/infrastructure-features: '["disconnected"]'
Expand Down Expand Up @@ -295,6 +295,8 @@ spec:
- description: Configure service certificate.
displayName: Service Certificate
path: service.certificate
- displayName: Knative Service
path: knative
- displayName: Monitoring
path: monitoring
- description: An array consisting of service ports.
Expand Down Expand Up @@ -328,6 +330,12 @@ spec:
- description: List of containers to run before other containers in a pod.
displayName: Init Containers
path: initContainers
- description: Annotations for Autoscaling.
displayName: Autoscaling Annotations
path: knative.autoscaling
- description: List of traffic targets.
displayName: Traffic Targets
path: knative.traffic
- description: List of sidecar containers. These are additional containers to
be added to the pods.
displayName: Sidecar Containers
Expand Down
8 changes: 8 additions & 0 deletions common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
corev1 "k8s.io/api/core/v1"
networkingv1 "k8s.io/api/networking/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
servingv1 "knative.dev/serving/pkg/apis/serving/v1"
)

// StatusConditionType ...
Expand Down Expand Up @@ -144,6 +145,12 @@ type BaseComponentMonitoring interface {
GetEndpoints() []prometheusv1.Endpoint
}

// BaseComponentKnativeService represents basic Knative service configuration
type BaseComponentKnativeService interface {
GetTrafficTarget() []servingv1.TrafficTarget
GetAutoscalingAnnotations() map[string]string
}

// BaseComponentRoute represents route configuration
type BaseComponentRoute interface {
GetTermination() *routev1.TLSTerminationType
Expand Down Expand Up @@ -222,6 +229,7 @@ type BaseComponent interface {
GetApplicationVersion() string
GetApplicationName() string
GetMonitoring() BaseComponentMonitoring
GetKnativeService() BaseComponentKnativeService
GetLabels() map[string]string
GetAnnotations() map[string]string
GetStatus() BaseComponentStatus
Expand Down
60 changes: 60 additions & 0 deletions config/crd/bases/rc.app.stacks_runtimecomponents.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2456,6 +2456,66 @@ spec:
x-kubernetes-list-map-keys:
- name
x-kubernetes-list-type: map
knative:
description: Specifies parameters for Knative Service.
properties:
autoscaling:
additionalProperties:
type: string
description: Annotations for Autoscaling.
type: object
traffic:
description: List of traffic targets.
items:
description: TrafficTarget holds a single entry of the routing
table for a Route.
properties:
configurationName:
description: ConfigurationName of a configuration to whose
latest revision we will send this portion of traffic.
When the "status.latestReadyRevisionName" of the referenced
configuration changes, we will automatically migrate traffic
from the prior "latest ready" revision to the new one. This
field is never set in Route's status, only its spec. This
is mutually exclusive with RevisionName.
type: string
latestRevision:
description: LatestRevision may be optionally provided to
indicate that the latest ready Revision of the Configuration
should be used for this traffic target. When provided
LatestRevision must be true if RevisionName is empty;
it must be false when RevisionName is non-empty.
type: boolean
percent:
description: 'Percent indicates that percentage based routing
should be used and the value indicates the percent of
traffic that is be routed to this Revision or Configuration.
`0` (zero) mean no traffic, `100` means all traffic. When
percentage based routing is being used the follow rules
apply: - the sum of all percent values must equal 100
- when not specified, the implied value for `percent`
is zero for that particular Revision or Configuration'
format: int64
type: integer
revisionName:
description: RevisionName of a specific revision to which
to send this portion of traffic. This is mutually exclusive
with ConfigurationName.
type: string
tag:
description: Tag is optionally used to expose a dedicated
url for referencing this target exclusively.
type: string
url:
description: URL displays the URL for accessing named traffic
targets. URL is displayed in status, and is disallowed
on spec. URL must contain a scheme (e.g. http://) and
a hostname, but may not contain anything else (e.g. basic
auth, url path, etc.)
type: string
type: object
type: array
type: object
manageTLS:
description: Enable management of TLS certificates. Defaults to true.
type: boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ spec:
- description: Configure service certificate.
displayName: Service Certificate
path: service.certificate
- displayName: Knative Service
path: knative
- displayName: Monitoring
path: monitoring
- description: An array consisting of service ports.
Expand Down Expand Up @@ -262,6 +264,12 @@ spec:
- description: List of containers to run before other containers in a pod.
displayName: Init Containers
path: initContainers
- description: Annotations for Autoscaling.
displayName: Autoscaling Annotations
path: knative.autoscaling
- description: List of traffic targets.
displayName: Traffic Targets
path: knative.traffic
- description: List of sidecar containers. These are additional containers to
be added to the pods.
displayName: Sidecar Containers
Expand Down
Loading