Skip to content

Commit 97ec688

Browse files
committed
Migrate to new Kubernentes event API
Signed-off-by: Adrian Fernandez De La Torre <adri1197@gmail.com>
1 parent 07d627d commit 97ec688

8 files changed

Lines changed: 305 additions & 20 deletions

File tree

apis/event/v1/action.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
Copyright 2022 The Flux authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1
18+
19+
// These constants define common event actions used throughout Flux controllers.
20+
const (
21+
// ActionReconciling indicates a reconciliation is in progress.
22+
ActionReconciling string = "Reconciling"
23+
// ActionReconciled indicates a successful reconciliation.
24+
ActionReconciled string = "Reconciled"
25+
// ActionFetching indicates fetching of a resource or artifact.
26+
ActionFetching string = "Fetching"
27+
// ActionFetched indicates successful fetch of a resource or artifact.
28+
ActionFetched string = "Fetched"
29+
// ActionApplying indicates applying changes to the cluster.
30+
ActionApplying string = "Applying"
31+
// ActionApplied indicates successful application of changes.
32+
ActionApplied string = "Applied"
33+
// ActionDeleting indicates deletion is in progress.
34+
ActionDeleting string = "Deleting"
35+
// ActionDeleted indicates successful deletion.
36+
ActionDeleted string = "Deleted"
37+
// ActionValidating indicates validation is in progress.
38+
ActionValidating string = "Validating"
39+
// ActionValidated indicates successful validation.
40+
ActionValidated string = "Validated"
41+
// ActionWaiting indicates waiting for a condition.
42+
ActionWaiting string = "Waiting"
43+
// ActionProgressing indicates progression through a workflow.
44+
ActionProgressing string = "Progressing"
45+
// ActionFailed indicates a failed operation.
46+
ActionFailed string = "Failed"
47+
)

apis/event/v1/doc.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
Copyright 2022 The Flux authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// package v1 contains the API Schema definitions for the Flux eventing API.
18+
// +kubebuilder:object:generate=true
19+
package v1

apis/event/v1/event.go

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
Copyright 2022 The Flux authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1
18+
19+
import (
20+
corev1 "k8s.io/api/core/v1"
21+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
)
23+
24+
// Group is the API Group for the Event API.
25+
const Group = "event.toolkit.fluxcd.io"
26+
27+
// These constants define valid event severity values.
28+
const (
29+
// EventSeverityTrace represents a trace event, usually
30+
// informing about actions taken during reconciliation.
31+
EventSeverityTrace string = "trace"
32+
// EventSeverityInfo represents an informational event, usually
33+
// informing about changes.
34+
EventSeverityInfo string = "info"
35+
// EventSeverityError represent an error event, usually a warning
36+
// that something goes wrong.
37+
EventSeverityError string = "error"
38+
)
39+
40+
// EventTypeTrace represents a trace event.
41+
const EventTypeTrace string = "Trace"
42+
43+
// Event is a report of an event issued by a controller.
44+
type Event struct {
45+
// The object that this event is about.
46+
// +required
47+
InvolvedObject corev1.ObjectReference `json:"involvedObject"`
48+
49+
// RelatedObject is an optional secondary object for more complex actions.
50+
// For simple events, this field may be left empty.
51+
// +optional
52+
RelatedObject corev1.ObjectReference `json:"relatedObject"`
53+
54+
// Severity type of this event (trace, info, error)
55+
// +kubebuilder:validation:Enum=trace;info;error
56+
// +required
57+
Severity string `json:"severity"`
58+
59+
// The time at which this event was recorded.
60+
// +required
61+
Timestamp metav1.Time `json:"timestamp"`
62+
63+
// A human-readable description of this event.
64+
// Maximum length 39,000 characters.
65+
// +kubebuilder:validation:MaxLength=39000
66+
// +required
67+
Message string `json:"message"`
68+
69+
// A machine understandable string that gives the reason
70+
// for the transition into the object's current status.
71+
// +required
72+
Reason string `json:"reason"`
73+
74+
// Action describes what action was taken/failed regarding the object.
75+
// Examples: "Starting", "Syncing", "Deleting".
76+
// +required
77+
Action string `json:"action"`
78+
79+
// Metadata of this event, e.g. apply change set.
80+
// +optional
81+
Metadata map[string]string `json:"metadata,omitempty"`
82+
83+
// Name of the controller that emitted this event, e.g. `source-controller`.
84+
// +required
85+
ReportingController string `json:"reportingController"`
86+
87+
// ID of the controller instance, e.g. `source-controller-xyzf`.
88+
// +optional
89+
ReportingInstance string `json:"reportingInstance,omitempty"`
90+
}
91+
92+
// HasReason returns true if the Reason equals the given value.
93+
func (in *Event) HasReason(reason string) bool {
94+
return in.Reason == reason
95+
}
96+
97+
// HasMetadata returns true if the given key/value pair is found in Metadata.
98+
func (in *Event) HasMetadata(key string, val string) bool {
99+
if v, ok := in.Metadata[key]; ok && v == val {
100+
return true
101+
}
102+
return false
103+
}
104+
105+
// GetRevision looks up for the keys in Metadata that may contain
106+
// the revision of the object that this event is about.
107+
func (in *Event) GetRevision() (string, bool) {
108+
if r, ok := in.Metadata[MetaCommitKey]; ok {
109+
return r, true
110+
}
111+
if r, ok := in.Metadata[MetaOriginRevisionKey]; ok {
112+
return r, true
113+
}
114+
if r, ok := in.Metadata[MetaRevisionKey]; ok {
115+
return r, true
116+
}
117+
return "", false
118+
}

apis/event/v1/metadata.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
Copyright 2022 The Flux authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1
18+
19+
// These constants define the Event metadata keys used throughout Flux controllers.
20+
const (
21+
// MetaRevisionKey is the key used to hold the source artifact revision.
22+
MetaRevisionKey string = "revision"
23+
// MetaOriginRevisionKey is the key used to hold the source artifact origin revision.
24+
MetaOriginRevisionKey string = "originRevision"
25+
// MetaChecksumKey is the key used to hold the source artifact checksum.
26+
// Deprecated: in favor of MetaDigestKey.
27+
MetaChecksumKey string = "checksum"
28+
// MetaDigestKey is the key used to hold the source artifact digest.
29+
MetaDigestKey string = "digest"
30+
// MetaTokenKey is the key used to hold an arbitrary token whose contents
31+
// are defined on a per-event-emitter basis for uniquely identifying the
32+
// contents of the event payload. For example, it could be the generation
33+
// of an object, or the hash of a set of configurations, or even a
34+
// base64-encoded set of configurations. This is useful for example for
35+
// rate limiting the events.
36+
MetaTokenKey string = "token"
37+
// MetaCommitKey is the key used to hold the Git commit hash.
38+
MetaCommitKey string = "commit"
39+
// MetaCommitStatusKey is the key used to signal a Git commit status event.
40+
MetaCommitStatusKey string = "commit_status"
41+
// MetaCommitStatusUpdateValue is the value of MetaCommitStatusKey
42+
// used to signal a Git commit status update.
43+
MetaCommitStatusUpdateValue string = "update"
44+
// MetaChangeRequestKey is the key used to hold the identifier of a change request.
45+
MetaChangeRequestKey string = "change_request"
46+
)

apis/event/v1/zz_generated.deepcopy.go

Lines changed: 45 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)