Skip to content

Commit

Permalink
feat: Introduce CloudEvents to KEDA (kedacore#4968)
Browse files Browse the repository at this point in the history
Co-authored-by: Jorge Turrado Ferrero <Jorge_turrado@hotmail.es>
Co-authored-by: Zbynek Roubalik <zroubalik@gmail.com>
Co-authored-by: Josef Karasek <karasek.jose@gmail.com>
Co-authored-by: Jan Wozniak <wozniak.jan@gmail.com>
Signed-off-by: anton.lysina <alysina@gmail.com>
  • Loading branch information
5 people authored and toniiiik committed Jan 15, 2024
1 parent 7c35220 commit 4aa9594
Show file tree
Hide file tree
Showing 118 changed files with 10,578 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ To learn more about active deprecations, we recommend checking [GitHub Discussio

Here is an overview of all new **experimental** features:

- **General**: TODO ([#XXX](https://github.com/kedacore/keda/issues/XXX))
- **General**: Emit CloudEvents on major KEDA events ([#3533](https://github.com/kedacore/keda/issues/3533))

### Improvements

Expand Down
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,16 @@ proto-gen: protoc-gen ## Generate Liiklus, ExternalScaler and MetricsService pro
PATH="$(LOCALBIN):$(PATH)" protoc -I vendor --proto_path=pkg/metricsservice/api metrics.proto --go_out=pkg/metricsservice/api --go-grpc_out=pkg/metricsservice/api

.PHONY: mockgen-gen
mockgen-gen: mockgen pkg/mock/mock_scaling/mock_interface.go pkg/mock/mock_scaling/mock_executor/mock_interface.go pkg/mock/mock_scaler/mock_scaler.go pkg/mock/mock_scale/mock_interfaces.go pkg/mock/mock_client/mock_interfaces.go pkg/scalers/liiklus/mocks/mock_liiklus.go pkg/mock/mock_secretlister/mock_interfaces.go
mockgen-gen: mockgen pkg/mock/mock_scaling/mock_interface.go pkg/mock/mock_scaling/mock_executor/mock_interface.go pkg/mock/mock_scaler/mock_scaler.go pkg/mock/mock_scale/mock_interfaces.go pkg/mock/mock_client/mock_interfaces.go pkg/scalers/liiklus/mocks/mock_liiklus.go pkg/mock/mock_secretlister/mock_interfaces.go pkg/mock/mock_eventemitter/mock_interface.go

pkg/mock/mock_scaling/mock_interface.go: pkg/scaling/scale_handler.go
$(MOCKGEN) -destination=$@ -package=mock_scaling -source=$^
pkg/mock/mock_scaling/mock_executor/mock_interface.go: pkg/scaling/executor/scale_executor.go
$(MOCKGEN) -destination=$@ -package=mock_executor -source=$^
pkg/mock/mock_scaler/mock_scaler.go: pkg/scalers/scaler.go
$(MOCKGEN) -destination=$@ -package=mock_scalers -source=$^
pkg/mock/mock_eventemitter/mock_interface.go: pkg/eventemitter/eventemitter.go
$(MOCKGEN) -destination=$@ -package=mock_eventemitter -source=$^
pkg/mock/mock_secretlister/mock_interfaces.go: vendor/k8s.io/client-go/listers/core/v1/secret.go
mkdir -p pkg/mock/mock_secretlister
$(MOCKGEN) k8s.io/client-go/listers/core/v1 SecretLister,SecretNamespaceLister > $@
Expand Down
85 changes: 85 additions & 0 deletions apis/eventing/v1alpha1/cloudeventsource_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
Copyright 2023 The KEDA 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 (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

v1alpha1 "github.com/kedacore/keda/v2/apis/keda/v1alpha1"
)

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// CloudEventSource defines how a KEDA event will be sent to event sink
// +kubebuilder:resource:path=cloudeventsources,scope=Namespaced
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Active",type="string",JSONPath=".status.conditions[?(@.type==\"Active\")].status"
type CloudEventSource struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec CloudEventSourceSpec `json:"spec"`
Status CloudEventSourceStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// CloudEventSourceList is a list of CloudEventSource resources
type CloudEventSourceList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
Items []CloudEventSource `json:"items"`
}

// CloudEventSourceSpec defines the spec of CloudEventSource
type CloudEventSourceSpec struct {
// +optional
ClusterName string `json:"clusterName,omitempty"`

Destination Destination `json:"destination"`
}

// CloudEventSourceStatus defines the observed state of CloudEventSource
// +optional
type CloudEventSourceStatus struct {
// +optional
Conditions v1alpha1.Conditions `json:"conditions,omitempty"`
}

// Destination defines the various ways to emit events
type Destination struct {
// +optional
HTTP *CloudEventHTTP `json:"http"`
}

type CloudEventHTTP struct {
URI string `json:"uri"`
}

func init() {
SchemeBuilder.Register(&CloudEventSource{}, &CloudEventSourceList{})
}

// GenerateIdentifier returns identifier for the object in for "kind.namespace.name"
func (t *CloudEventSource) GenerateIdentifier() string {
return v1alpha1.GenerateIdentifier("CloudEventSource", t.Namespace, t.Name)
}

// GetCloudEventSourceInitializedConditions returns CloudEventSource Conditions initialized to the default -> Status: Unknown
func GetCloudEventSourceInitializedConditions() *v1alpha1.Conditions {
return &v1alpha1.Conditions{{Type: v1alpha1.ConditionActive, Status: metav1.ConditionUnknown}}
}
28 changes: 28 additions & 0 deletions apis/eventing/v1alpha1/condition_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
Copyright 2023 The KEDA 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

const (
// CloudEventSourceConditionActiveReason defines the active condition reason for CloudEventSource
CloudEventSourceConditionActiveReason = "CloudEventSourceActive"
// CloudEventSourceConditionFailedReason defines the failed condition reason for CloudEventSource
CloudEventSourceConditionFailedReason = "CloudEventSourceFailed"
// CloudEventSourceConditionActiveMessage defines the active condition message for CloudEventSource
CloudEventSourceConditionActiveMessage = "Is configured to send events to the configured destination"
// CloudEventSourceConditionFailedMessage defines the failed condition message for CloudEventSource
CloudEventSourceConditionFailedMessage = "Failed to send events to the configured destination"
)
36 changes: 36 additions & 0 deletions apis/eventing/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Copyright 2023 The KEDA 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 contains API Schema definitions for the eventing v1alpha1 API group
// +kubebuilder:object:generate=true
// +groupName=eventing.keda.sh
package v1alpha1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "eventing.keda.sh", Version: "v1alpha1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
)
156 changes: 156 additions & 0 deletions apis/eventing/v1alpha1/zz_generated.deepcopy.go

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

4 changes: 2 additions & 2 deletions apis/keda/v1alpha1/condition_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ const (
)

const (
// ScaledObjectConditionReadySucccesReason defines the default Reason for correct ScaledObject
ScaledObjectConditionReadySucccesReason = "ScaledObjectReady"
// ScaledObjectConditionReadySuccessReason defines the default Reason for correct ScaledObject
ScaledObjectConditionReadySuccessReason = "ScaledObjectReady"
// ScaledObjectConditionReadySuccessMessage defines the default Message for correct ScaledObject
ScaledObjectConditionReadySuccessMessage = "ScaledObject is defined correctly and is ready for scaling"
// ScaledObjectConditionPausedReason defines the default Reason for paused ScaledObject
Expand Down
Loading

0 comments on commit 4aa9594

Please sign in to comment.