Skip to content

Commit eaf9ac6

Browse files
committed
feat: initial controller implementation
Signed-off-by: Bence Csati <[email protected]>
1 parent 00dab36 commit eaf9ac6

File tree

10 files changed

+109
-65
lines changed

10 files changed

+109
-65
lines changed

charts/logging-operator/charts/logging-operator-crds/templates/logging.banzaicloud.io_axosyslogs.yaml

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ spec:
2020
scope: Namespaced
2121
versions:
2222
- additionalPrinterColumns:
23-
- description: Control namespace
24-
jsonPath: .spec.controlNamespace
25-
name: ControlNamespace
26-
type: string
2723
- description: Number of problems
2824
jsonPath: .status.problemsCount
2925
name: Problems
@@ -40,14 +36,14 @@ spec:
4036
type: object
4137
spec:
4238
properties:
43-
controlNamespace:
44-
type: string
45-
x-kubernetes-validations:
46-
- message: Value is immutable, please recreate the resource
47-
rule: self == oldSelf
4839
destinations:
4940
items:
50-
type: string
41+
properties:
42+
config:
43+
type: string
44+
name:
45+
type: string
46+
type: object
5147
type: array
5248
logPaths:
5349
items:
@@ -58,8 +54,6 @@ spec:
5854
type: string
5955
type: object
6056
type: array
61-
required:
62-
- controlNamespace
6357
type: object
6458
status:
6559
properties:

charts/logging-operator/crds/logging.banzaicloud.io_axosyslogs.yaml

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ spec:
1717
scope: Namespaced
1818
versions:
1919
- additionalPrinterColumns:
20-
- description: Control namespace
21-
jsonPath: .spec.controlNamespace
22-
name: ControlNamespace
23-
type: string
2420
- description: Number of problems
2521
jsonPath: .status.problemsCount
2622
name: Problems
@@ -37,14 +33,14 @@ spec:
3733
type: object
3834
spec:
3935
properties:
40-
controlNamespace:
41-
type: string
42-
x-kubernetes-validations:
43-
- message: Value is immutable, please recreate the resource
44-
rule: self == oldSelf
4536
destinations:
4637
items:
47-
type: string
38+
properties:
39+
config:
40+
type: string
41+
name:
42+
type: string
43+
type: object
4844
type: array
4945
logPaths:
5046
items:
@@ -55,8 +51,6 @@ spec:
5551
type: string
5652
type: object
5753
type: array
58-
required:
59-
- controlNamespace
6054
type: object
6155
status:
6256
properties:

charts/logging-operator/templates/clusterrole.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ rules:
156156
- apiGroups:
157157
- logging.banzaicloud.io
158158
resources:
159+
- axosyslogs
159160
- clusterflows
160161
- clusteroutputs
161162
- flows
@@ -181,6 +182,7 @@ rules:
181182
- apiGroups:
182183
- logging.banzaicloud.io
183184
resources:
185+
- axosyslogs/status
184186
- clusterflows/status
185187
- clusteroutputs/status
186188
- flows/status

config/crd/bases/logging.banzaicloud.io_axosyslogs.yaml

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ spec:
1717
scope: Namespaced
1818
versions:
1919
- additionalPrinterColumns:
20-
- description: Control namespace
21-
jsonPath: .spec.controlNamespace
22-
name: ControlNamespace
23-
type: string
2420
- description: Number of problems
2521
jsonPath: .status.problemsCount
2622
name: Problems
@@ -37,14 +33,14 @@ spec:
3733
type: object
3834
spec:
3935
properties:
40-
controlNamespace:
41-
type: string
42-
x-kubernetes-validations:
43-
- message: Value is immutable, please recreate the resource
44-
rule: self == oldSelf
4536
destinations:
4637
items:
47-
type: string
38+
properties:
39+
config:
40+
type: string
41+
name:
42+
type: string
43+
type: object
4844
type: array
4945
logPaths:
5046
items:
@@ -55,8 +51,6 @@ spec:
5551
type: string
5652
type: object
5753
type: array
58-
required:
59-
- controlNamespace
6054
type: object
6155
status:
6256
properties:

config/rbac/role.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ rules:
149149
- apiGroups:
150150
- logging.banzaicloud.io
151151
resources:
152+
- axosyslogs
152153
- clusterflows
153154
- clusteroutputs
154155
- flows
@@ -174,6 +175,7 @@ rules:
174175
- apiGroups:
175176
- logging.banzaicloud.io
176177
resources:
178+
- axosyslogs/status
177179
- clusterflows/status
178180
- clusteroutputs/status
179181
- flows/status

controllers/logging/axosyslog_controller.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,58 @@
1313
// limitations under the License.
1414

1515
package controllers
16+
17+
import (
18+
"context"
19+
20+
"github.com/go-logr/logr"
21+
ctrl "sigs.k8s.io/controller-runtime"
22+
"sigs.k8s.io/controller-runtime/pkg/client"
23+
24+
"github.com/kube-logging/logging-operator/pkg/sdk/logging/api/v1beta1"
25+
)
26+
27+
// NewAxoSyslogReconciler creates a new AxoSyslogReconciler instance
28+
func NewAxoSyslogReconciler(client client.Client, log logr.Logger) *AxoSyslogReconciler {
29+
return &AxoSyslogReconciler{
30+
Client: client,
31+
Log: log,
32+
}
33+
}
34+
35+
type AxoSyslogReconciler struct {
36+
client.Client
37+
Log logr.Logger
38+
}
39+
40+
// +kubebuilder:rbac:groups=logging.banzaicloud.io,resources=axosyslogs,verbs=get;list;watch;create;update;patch;delete
41+
// +kubebuilder:rbac:groups=logging.banzaicloud.io,resources=axosyslogs/status,verbs=get;update;patch
42+
// +kubebuilder:rbac:groups="",resources=configmaps;secrets,verbs=get;list;watch;create;update;patch;delete
43+
// +kubebuilder:rbac:groups=apps,resources=statefulsets,verbs=get;list;watch;create;update;patch;delete
44+
// +kubebuilder:rbac:groups="",resources=services;persistentvolumeclaims;serviceaccounts;pods,verbs=get;list;watch;create;update;patch;delete
45+
// +kubebuilder:rbac:groups="rbac.authorization.k8s.io",resources=clusterroles;clusterrolebindings;roles;rolebindings,verbs=get;list;watch;create;update;patch;delete
46+
47+
// Reconciles axosyslog resource
48+
func (r *AxoSyslogReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
49+
log := r.Log.WithValues("axosyslog", req.NamespacedName)
50+
51+
log.V(1).Info("Reconciling AxoSyslog")
52+
53+
var axosyslog v1beta1.AxoSyslog
54+
if err := r.Get(ctx, req.NamespacedName, &axosyslog); err != nil {
55+
return ctrl.Result{}, client.IgnoreNotFound(err)
56+
}
57+
58+
if err := axosyslog.SetDefaults(); err != nil {
59+
return ctrl.Result{}, err
60+
}
61+
62+
return ctrl.Result{}, nil
63+
}
64+
65+
func SetupAxoSyslogWithManager(mgr ctrl.Manager, logger logr.Logger) error {
66+
return ctrl.NewControllerManagedBy(mgr).
67+
For(&v1beta1.AxoSyslog{}).
68+
Named("AxoSyslogController").
69+
Complete(NewAxoSyslogReconciler(mgr.GetClient(), logger))
70+
}

docs/configuration/crds/v1beta1/axosyslog_types.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,7 @@ AxoSyslog is the Schema for the AxoSyslogs API
1919

2020
AxoSyslogSpec defines the desired state of AxoSyslog
2121

22-
### controlNamespace (string, required) {#axosyslogspec-controlnamespace}
23-
24-
ControlNamespace is the namespace where the AxoSyslog StatefulSet and related components will be deployed
25-
26-
27-
### destinations ([]string, optional) {#axosyslogspec-destinations}
22+
### destinations ([]Destination, optional) {#axosyslogspec-destinations}
2823

2924
Destinations is a list of destinations to be rendered in the AxoSyslog configuration
3025

@@ -41,7 +36,7 @@ LogPath defines a single log path that will be rendered in the AxoSyslog configu
4136

4237
### destination (string, optional) {#logpath-destination}
4338

44-
name of a destionation to be used in the log path
39+
name of a destination to be used in the log path
4540

4641

4742
### filterx (string, optional) {#logpath-filterx}
@@ -112,7 +107,7 @@ AxoSyslogList contains a list of AxoSyslog
112107
### (metav1.TypeMeta, required) {#axosysloglist-}
113108

114109

115-
### metadata (metav1.ListMeta, required) {#axosysloglist-metadata}
110+
### metadata (metav1.ListMeta, optional) {#axosysloglist-metadata}
116111

117112

118113
### items ([]AxoSyslog, required) {#axosysloglist-items}

main.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,15 @@ import (
5151
"sigs.k8s.io/controller-runtime/pkg/webhook"
5252
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
5353

54-
telemetryv1alpha1 "github.com/kube-logging/telemetry-controller/api/telemetry/v1alpha1"
55-
5654
extensionsControllers "github.com/kube-logging/logging-operator/controllers/extensions"
57-
loggingControllers "github.com/kube-logging/logging-operator/controllers/logging"
55+
controllers "github.com/kube-logging/logging-operator/controllers/logging"
5856
extensionsv1alpha1 "github.com/kube-logging/logging-operator/pkg/sdk/extensions/api/v1alpha1"
5957
config "github.com/kube-logging/logging-operator/pkg/sdk/extensions/extensionsconfig"
6058
loggingv1alpha1 "github.com/kube-logging/logging-operator/pkg/sdk/logging/api/v1alpha1"
6159
loggingv1beta1 "github.com/kube-logging/logging-operator/pkg/sdk/logging/api/v1beta1"
6260
"github.com/kube-logging/logging-operator/pkg/sdk/logging/model/types"
6361
"github.com/kube-logging/logging-operator/pkg/webhook/podhandler"
62+
telemetryv1alpha1 "github.com/kube-logging/telemetry-controller/api/telemetry/v1alpha1"
6463
// +kubebuilder:scaffold:imports
6564
)
6665

@@ -194,7 +193,7 @@ func main() {
194193
os.Exit(1)
195194
}
196195

197-
loggingReconciler := loggingControllers.NewLoggingReconciler(mgr.GetClient(), mgr.GetEventRecorderFor("logging-operator"), ctrl.Log.WithName("logging"))
196+
loggingReconciler := controllers.NewLoggingReconciler(mgr.GetClient(), mgr.GetEventRecorderFor("logging-operator"), ctrl.Log.WithName("logging"))
198197

199198
if err := (&extensionsControllers.EventTailerReconciler{
200199
Client: mgr.GetClient(),
@@ -213,23 +212,28 @@ func main() {
213212
os.Exit(1)
214213
}
215214

216-
if err := loggingControllers.SetupLoggingWithManager(mgr, ctrl.Log.WithName("manager")).Complete(loggingReconciler); err != nil {
215+
if err := controllers.SetupLoggingWithManager(mgr, ctrl.Log.WithName("manager")).Complete(loggingReconciler); err != nil {
217216
setupLog.Error(err, "unable to create controller", "controller", "Logging")
218217
os.Exit(1)
219218
}
220219

221-
if err := loggingControllers.SetupLoggingRouteWithManager(mgr, ctrl.Log.WithName("logging-route")); err != nil {
220+
if err := controllers.SetupLoggingRouteWithManager(mgr, ctrl.Log.WithName("logging-route")); err != nil {
222221
setupLog.Error(err, "unable to create controller", "controller", "LoggingRoute")
223222
os.Exit(1)
224223
}
225224

226225
if enableTelemetryControllerRoute {
227-
if err := loggingControllers.SetupTelemetryControllerWithManager(mgr, ctrl.Log.WithName("telemetry-controller")); err != nil {
226+
if err := controllers.SetupTelemetryControllerWithManager(mgr, ctrl.Log.WithName("telemetry-controller")); err != nil {
228227
setupLog.Error(err, "unable to create controller", "controller", "TelemetryController")
229228
os.Exit(1)
230229
}
231230
}
232231

232+
if err := controllers.SetupAxoSyslogWithManager(mgr, ctrl.Log.WithName("axosyslog")); err != nil {
233+
setupLog.Error(err, "unable to create controller", "controller", "AxoSyslog")
234+
os.Exit(1)
235+
}
236+
233237
if os.Getenv("ENABLE_WEBHOOKS") == "true" {
234238
if err := loggingv1beta1.SetupWebhookWithManager(mgr, loggingv1beta1.APITypes()...); err != nil {
235239
setupLog.Error(err, "unable to create webhook", "webhook", "v1beta1.logging")
@@ -399,9 +403,9 @@ func cleanupFinalizers(ctx context.Context, client client.Client) {
399403
}
400404

401405
finalizers := []string{
402-
loggingControllers.FluentdConfigFinalizer,
403-
loggingControllers.SyslogNGConfigFinalizer,
404-
loggingControllers.TelemetryControllerFinalizer,
406+
controllers.FluentdConfigFinalizer,
407+
controllers.SyslogNGConfigFinalizer,
408+
controllers.TelemetryControllerFinalizer,
405409
}
406410
for _, logging := range loggingList.Items {
407411
for _, finalizer := range finalizers {

pkg/sdk/logging/api/v1beta1/axosyslog_types.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2020
// +kubebuilder:subresource:status
2121
// +kubebuilder:resource:path=axosyslogs,scope=Namespaced,categories=logging-all
2222
// +kubebuilder:storageversion
23-
// +kubebuilder:printcolumn:name="ControlNamespace",type="string",JSONPath=".spec.controlNamespace",description="Control namespace"
2423
// +kubebuilder:printcolumn:name="Problems",type="integer",JSONPath=".status.problemsCount",description="Number of problems"
2524

2625
// AxoSyslog is the Schema for the AxoSyslogs API
@@ -34,24 +33,18 @@ type AxoSyslog struct {
3433

3534
// AxoSyslogSpec defines the desired state of AxoSyslog
3635
type AxoSyslogSpec struct {
37-
// +kubebuilder:validation:Required
38-
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable, please recreate the resource"
39-
40-
// ControlNamespace is the namespace where the AxoSyslog StatefulSet and related components will be deployed
41-
ControlNamespace string `json:"controlNamespace"`
42-
4336
// LogPaths is a list of log paths to be rendered in the AxoSyslog configuration
4437
LogPaths []LogPath `json:"logPaths,omitempty"`
4538

4639
// Destinations is a list of destinations to be rendered in the AxoSyslog configuration
47-
Destinations []string `json:"destinations,omitempty"`
40+
Destinations []Destination `json:"destinations,omitempty"`
4841
}
4942

5043
// LogPath defines a single log path that will be rendered in the AxoSyslog configuration
5144
type LogPath struct {
5245
// filterx block to be rendered within the log path
5346
Filterx string `json:"filterx,omitempty"`
54-
// name of a destionation to be used in the log path
47+
// name of a destination to be used in the log path
5548
Destination string `json:"destination,omitempty"`
5649
}
5750

@@ -90,10 +83,21 @@ type OTLPSource struct {
9083
// AxoSyslogList contains a list of AxoSyslog
9184
type AxoSyslogList struct {
9285
metav1.TypeMeta `json:",inline"`
93-
metav1.ListMeta `json:"metadata,omitzero"`
86+
metav1.ListMeta `json:"metadata,omitempty"`
9487
Items []AxoSyslog `json:"items"`
9588
}
9689

9790
func init() {
9891
SchemeBuilder.Register(&AxoSyslog{}, &AxoSyslogList{})
9992
}
93+
94+
func (a *AxoSyslog) SetDefaults() error {
95+
if a.Spec.LogPaths == nil {
96+
a.Spec.LogPaths = []LogPath{}
97+
}
98+
if a.Spec.Destinations == nil {
99+
a.Spec.Destinations = []Destination{}
100+
}
101+
102+
return nil
103+
}

pkg/sdk/logging/api/v1beta1/zz_generated.deepcopy.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)