Skip to content

Commit 7c6a6e0

Browse files
baluchickenahma
authored andcommitted
Allow to add config values through crds (#59)
1 parent 160036c commit 7c6a6e0

File tree

13 files changed

+308
-102
lines changed

13 files changed

+308
-102
lines changed

deploy/crds/logging_v1alpha1_fluentbit_cr.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,14 @@ metadata:
66
release: test
77
spec:
88
namespace: default
9+
annotations:
10+
prometheus.io/scrape: "true"
11+
prometheus.io/path: "/api/v1/metrics/prometheus"
12+
prometheus.io/port: "2020"
913
tls:
1014
enabled: false
15+
image:
16+
tag: "latest"
17+
repository: "fluent/fluent-bit"
18+
pullPolicy: "IfNotPresent"
19+
resources: {}

deploy/crds/logging_v1alpha1_fluentd_cr.yaml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,28 @@ metadata:
66
release: test
77
spec:
88
namespace: default
9+
annotations:
10+
prometheus.io/scrape: "true"
11+
prometheus.io/path: "/metrics"
12+
prometheus.io/port: "25000"
913
tls:
10-
enabled: false
14+
enabled: false
15+
image:
16+
tag: "v1.1.4"
17+
repository: "banzaicloud/fluentd"
18+
pullPolicy: "IfNotPresent"
19+
volumeModImage:
20+
tag: "latest"
21+
repository: "busybox"
22+
pullPolicy: "IfNotPresent"
23+
configReloaderImage:
24+
tag: "v0.2.2"
25+
repository: "jimmidyson/configmap-reload"
26+
pullPolicy: "IfNotPresent"
27+
resources: {}
28+
fluentdPvcSpec:
29+
accessModes:
30+
- ReadWriteOnce
31+
resources:
32+
requests:
33+
storage: 21Gi
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright © 2019 Banzai Cloud
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 v1alpha1
18+
19+
// ImageSpec struct hold information about image specification
20+
type ImageSpec struct {
21+
Repository string `json:"repository"`
22+
Tag string `json:"tag"`
23+
PullPolicy string `json:"pullPolicy"`
24+
}

pkg/apis/logging/v1alpha1/fluentbit_types.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
package v1alpha1
1818

1919
import (
20+
"strconv"
21+
22+
corev1 "k8s.io/api/core/v1"
2023
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2124
)
2225

@@ -29,8 +32,11 @@ type FluentbitSpec struct {
2932
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
3033
// Important: Run "operator-sdk generate k8s" to regenerate code after modifying this file
3134
// Add custom validation using kubebuilder tags: https://book.kubebuilder.io/beyond_basics/generating_crd.html
32-
Namespace string `json:"namespace"`
33-
TLS FluentbitTLS `json:"tls"`
35+
Namespace string `json:"namespace"`
36+
Annotations map[string]string `json:"annotations"`
37+
Image ImageSpec `json:"image"`
38+
TLS FluentbitTLS `json:"tls"`
39+
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
3440
}
3541

3642
// FluentbitTLS defines the TLS configs
@@ -69,6 +75,15 @@ type FluentbitList struct {
6975
Items []Fluentbit `json:"items"`
7076
}
7177

78+
// GetPrometheusPortFromAnnotation gets the port value from annotation
79+
func (spec FluentbitSpec) GetPrometheusPortFromAnnotation() int32 {
80+
port, err := strconv.ParseInt(spec.Annotations["prometheus.io/port"], 10, 32)
81+
if err != nil {
82+
panic(err)
83+
}
84+
return int32(port)
85+
}
86+
7287
func init() {
7388
SchemeBuilder.Register(&Fluentbit{}, &FluentbitList{})
7489
}

pkg/apis/logging/v1alpha1/fluentd_types.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
package v1alpha1
1818

1919
import (
20+
"strconv"
21+
22+
corev1 "k8s.io/api/core/v1"
2023
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2124
)
2225

@@ -29,8 +32,14 @@ type FluentdSpec struct {
2932
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
3033
// Important: Run "operator-sdk generate k8s" to regenerate code after modifying this file
3134
// Add custom validation using kubebuilder tags: https://book.kubebuilder.io/beyond_basics/generating_crd.html
32-
Namespace string `json:"namespace"`
33-
TLS FluentdTLS `json:"tls"`
35+
Namespace string `json:"namespace"`
36+
Annotations map[string]string `json:"annotations"`
37+
TLS FluentdTLS `json:"tls"`
38+
Image ImageSpec `json:"image"`
39+
FluentdPvcSpec corev1.PersistentVolumeClaimSpec `json:"fluentdPvcSpec"`
40+
VolumeModImage ImageSpec `json:"volumeModImage"`
41+
ConfigReloaderImage ImageSpec `json:"configReloaderImage"`
42+
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
3443
}
3544

3645
// FluentdTLS defines the TLS configs
@@ -69,6 +78,15 @@ type FluentdList struct {
6978
Items []Fluentd `json:"items"`
7079
}
7180

81+
// GetPrometheusPortFromAnnotation gets the port value from annotation
82+
func (spec FluentdSpec) GetPrometheusPortFromAnnotation() int32 {
83+
port, err := strconv.ParseInt(spec.Annotations["prometheus.io/port"], 10, 32)
84+
if err != nil {
85+
panic(err)
86+
}
87+
return int32(port)
88+
}
89+
7290
func init() {
7391
SchemeBuilder.Register(&Fluentd{}, &FluentdList{})
7492
}

pkg/apis/logging/v1alpha1/zz_generated.deepcopy.go

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

0 commit comments

Comments
 (0)