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

Refactor reconcilers and introduce v1beta2 API #435

Merged
merged 26 commits into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
974a77d
Refactor reconcilers and introduce v1beta2 API
stefanprodan Oct 27, 2022
9f2d0e1
Generate unique commit status updates
stefanprodan Oct 27, 2022
8dadcac
api: Add validation to URLs (max 2048) and Summary (max 255)
stefanprodan Oct 27, 2022
a9ac01a
Avoid key collision for BitBucket status updates
stefanprodan Oct 27, 2022
ab92536
docs: Add the API spec for Alerts v1beta2
stefanprodan Oct 27, 2022
ab5cdc8
docs: Add the API spec for Events and Providers v1beta2
stefanprodan Oct 28, 2022
613111c
docs: Add the API spec for Receivers v1beta2
stefanprodan Oct 31, 2022
5fd17e6
Refactor the Receiver URL generation
stefanprodan Nov 4, 2022
2b35ef5
API: Consolidate the documentation style for v1beta2
stefanprodan Nov 4, 2022
ae65712
Add reconciliation interval to providers and receivers
stefanprodan Nov 7, 2022
ee2600a
Issue warning events on reconciliation errors
stefanprodan Nov 8, 2022
caec764
Refactor notifies to use Flux Event API v1beta1
stefanprodan Nov 8, 2022
012faa2
Log and emit events on successful reconciliation
stefanprodan Nov 10, 2022
70c678f
Make interval optional
stefanprodan Nov 11, 2022
1a4a4a8
Validate the provider inline address and proxy
stefanprodan Nov 14, 2022
c9a774f
Compact success events
stefanprodan Nov 14, 2022
d16588a
Deprecate `Receiver.status.url` in favor of `.status.webhookPath`
stefanprodan Nov 15, 2022
5a0d6dd
Use `ProgressingWithRetry` from `fluxcd/pkg/apis/meta`
stefanprodan Nov 15, 2022
4aad301
Stall providers with invalid spec
stefanprodan Nov 16, 2022
831785a
docs: Add status and events to examples
stefanprodan Nov 16, 2022
04f5288
docs: Add alert status specification
stefanprodan Nov 16, 2022
78fe519
docs: Add commit status updates to providers spec
stefanprodan Nov 16, 2022
20fa1a0
docs: Add Provider and Receiver status spec
stefanprodan Nov 16, 2022
ef94247
docs: improve Receiver spec
hiddeco Nov 18, 2022
b0c02d7
config: ensure event create/patch is registered
hiddeco Nov 21, 2022
16012ce
docs: Rewrite portion of Provider spec
hiddeco Nov 25, 2022
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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
IMG ?= fluxcd/notification-controller:latest
# Produce CRDs that work back to Kubernetes 1.16
CRD_OPTIONS ?= crd:crdVersions=v1
SOURCE_VER ?= v0.24.0
SOURCE_VER ?= v0.31.0
pjbgf marked this conversation as resolved.
Show resolved Hide resolved

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
Expand Down Expand Up @@ -76,7 +76,7 @@ manifests: controller-gen

# Generate API reference documentation
api-docs: gen-crd-api-reference-docs
$(GEN_CRD_API_REFERENCE_DOCS) -api-dir=./api/v1beta1 -config=./hack/api-docs/config.json -template-dir=./hack/api-docs/template -out-file=./docs/api/notification.md
$(GEN_CRD_API_REFERENCE_DOCS) -api-dir=./api/v1beta2 -config=./hack/api-docs/config.json -template-dir=./hack/api-docs/template -out-file=./docs/api/notification.md

# Run go mod tidy
tidy:
Expand Down
9 changes: 9 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,13 @@ resources:
- group: notification
kind: Receiver
version: v1beta1
- group: notification
kind: Provider
version: v1beta2
- group: notification
kind: Alert
version: v1beta2
- group: notification
kind: Receiver
version: v1beta2
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's also add or update the sample CRDs in config/samples for these new APIs. They are useful for quickly referring to samples.

Copy link
Member Author

Choose a reason for hiding this comment

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

I left them on v1beta1 to test the API upgrade hooks, I'll update them to v1beta2 once we're close to the finish line with this PR.

version: "2"
2 changes: 1 addition & 1 deletion api/v1beta1/zz_generated.deepcopy.go

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

115 changes: 115 additions & 0 deletions api/v1beta2/alert_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
Copyright 2022 The Flux 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 v1beta2

import (
"github.com/fluxcd/pkg/apis/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const (
AlertKind string = "Alert"
)

// AlertSpec defines an alerting rule for events involving a list of objects.
type AlertSpec struct {
// ProviderRef specifies which Provider this Alert should use.
// +required
ProviderRef meta.LocalObjectReference `json:"providerRef"`

// EventSeverity specifies how to filter events based on severity.
// If set to 'info' no events will be filtered.
// +kubebuilder:validation:Enum=info;error
// +kubebuilder:default:=info
// +optional
EventSeverity string `json:"eventSeverity,omitempty"`

// EventSources specifies how to filter events based
// on the involved object kind, name and namespace.
// +required
EventSources []CrossNamespaceObjectReference `json:"eventSources"`

// ExclusionList specifies a list of Golang regular expressions
// to be used for excluding messages.
// +optional
ExclusionList []string `json:"exclusionList,omitempty"`

// Summary holds a short description of the impact and affected cluster.
// +kubebuilder:validation:MaxLength:=255
// +optional
Summary string `json:"summary,omitempty"`

// Suspend tells the controller to suspend subsequent
// events handling for this Alert.
// +optional
Suspend bool `json:"suspend,omitempty"`
}

// AlertStatus defines the observed state of the Alert.
type AlertStatus struct {
meta.ReconcileRequestStatus `json:",inline"`

// Conditions holds the conditions for the Alert.
// +optional
Conditions []metav1.Condition `json:"conditions,omitempty"`

// ObservedGeneration is the last observed generation.
// +optional
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
}

// +genclient
// +genclient:Namespaced
// +kubebuilder:storageversion
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description=""
// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.conditions[?(@.type==\"Ready\")].status",description=""
// +kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.conditions[?(@.type==\"Ready\")].message",description=""

// Alert is the Schema for the alerts API
type Alert struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec AlertSpec `json:"spec,omitempty"`
// +kubebuilder:default:={"observedGeneration":-1}
Status AlertStatus `json:"status,omitempty"`
}

// GetConditions returns the status conditions of the object.
func (in *Alert) GetConditions() []metav1.Condition {
return in.Status.Conditions
}

// SetConditions sets the status conditions on the object.
func (in *Alert) SetConditions(conditions []metav1.Condition) {
in.Status.Conditions = conditions
}

// +kubebuilder:object:root=true

// AlertList contains a list of Alerts.
type AlertList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Alert `json:"items"`
}

func init() {
SchemeBuilder.Register(&Alert{}, &AlertList{})
}
31 changes: 31 additions & 0 deletions api/v1beta2/condition_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
Copyright 2022 The Flux 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 v1beta2

const NotificationFinalizer = "finalizers.fluxcd.io"

const (
// InitializedReason represents the fact that a given resource has been initialized.
InitializedReason string = "Initialized"

// ValidationFailedReason represents the fact that some part of the spec of a given resource
// couldn't be validated.
ValidationFailedReason string = "ValidationFailed"

// TokenNotFoundReason represents the fact that receiver token can't be found.
TokenNotFoundReason string = "TokenNotFound"
)
20 changes: 20 additions & 0 deletions api/v1beta2/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
Copyright 2022 The Flux 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 v1beta2 contains API Schema definitions for the notification v1beta2 API group.
// +kubebuilder:object:generate=true
// +groupName=notification.toolkit.fluxcd.io
package v1beta2
33 changes: 33 additions & 0 deletions api/v1beta2/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
Copyright 2022 The Flux 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 v1beta2

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: "notification.toolkit.fluxcd.io", Version: "v1beta2"}

// 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
)
Loading