Skip to content

Commit

Permalink
changed logging to only support syslogng and elasticsearch.
Browse files Browse the repository at this point in the history
When a user wants logging, now automatcially SyslogNGOutput
and SyslogNGFlow objects are created. In addition, support for
Splunk has been removed and only Elasticsearch Outputs are supported.
A test case has been modified due to a known issue whiich should be
fixed in the next release of loggig-operator (kube-logging/logging-operator#1140)

Signed-off-by: mzeevi <meytar80@gmail.com>
  • Loading branch information
mzeevi committed Apr 22, 2024
1 parent a05f4c3 commit e105680
Show file tree
Hide file tree
Showing 22 changed files with 507 additions and 536 deletions.
32 changes: 12 additions & 20 deletions api/v1alpha1/capp_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,35 +107,27 @@ type RouteSpec struct {
// LogSpec defines the configuration for shipping Capp logs.
type LogSpec struct {
// Type defines where to send the Capp logs
// Possible values : "elastic" and "splunk".
// +kubebuilder:default:="elastic"
// +kubebuilder:validation:Enum=elastic
// +optional
Type string `json:"type,omitempty"`

// Host defines Elasticsearch or Splunk host.
// +optional
Host string `json:"host,omitempty"`

// SSLVerify determines whether to skip ssl verification.
// +optional
SSLVerify bool `json:"sslVerify,omitempty"`

// Index defines the index name to write events to.
// +optional
Index string `json:"index,omitempty"`

// UserName defines a User for authentication.
// User defines a User for authentication.
// +optional
UserName string `json:"username,omitempty"`
User string `json:"username,omitempty"`

// PasswordSecretName defines the name of the secret
// PasswordSecret defines the name of the secret
// containing the password for authentication.
// +optional
PasswordSecretName string `json:"passwordSecretName,omitempty"`

// HecTokenSecretName defines the name of the secret
// containing the Splunk Hec token.
// +optional
HecTokenSecretName string `json:"hecTokenSecretName,omitempty"`
PasswordSecret string `json:"passwordSecretName,omitempty"`
}

// ApplicationLinks contains relevant information about
Expand Down Expand Up @@ -171,17 +163,17 @@ type StateStatus struct {
LastChange metav1.Time `json:"lastChange,omitempty"`
}

// LoggingStatus defines the state of the Flow and Output objects linked to the Capp.
// LoggingStatus defines the state of the SyslogNGFlow and SyslogNGOutput objects linked to the Capp.
type LoggingStatus struct {
// Flow represents the Status of the Flow used by the Capp.
// SyslogNGFlow represents the Status of the SyslogNGFlow used by the Capp.
// +optional
Flow loggingv1beta1.FlowStatus `json:"flow,omitempty"`
SyslogNGFlow loggingv1beta1.SyslogNGFlowStatus `json:"syslogngflow,omitempty"`

// Output represents the Status of the Output used by the Capp.
// SyslogNGOutput represents the Status of the SyslogNGOutput used by the Capp.
// +optional
Output loggingv1beta1.OutputStatus `json:"output,omitempty"`
SyslogNGOutput loggingv1beta1.SyslogNGOutputStatus `json:"syslogngoutput,omitempty"`

// Conditions contain details about the current state of the Output and Flow used by the Capp.
// Conditions contain details about the current state of the SyslogNGFlow and SyslogNGOutput used by the Capp.
// +optional
Conditions []metav1.Condition `json:"conditions,omitempty"`
}
Expand Down
4 changes: 2 additions & 2 deletions api/v1alpha1/zz_generated.deepcopy.go

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

42 changes: 42 additions & 0 deletions capp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
apiVersion: rcs.dana.io/v1alpha1
kind: Capp
metadata:
name: capp-sample
namespace: capp-sample
spec:
configurationSpec:
template:
spec:
containers:
- env:
- name: APP_NAME
value: capp-env-var
image: 'quay.io/danateamorg/example-python-app:v1-flask'
name: capp-sample
volumeMounts:
- name: testpvc
mountPath: /data
volumes:
- name: testpvc
persistentVolumeClaim:
claimName: nfspvc
readOnly: false
routeSpec:
hostname: capp.dev
tlsEnabled: true
tlsSecret: cappTlsSecretName
volumesSpec:
nfsVolumes:
- server: test
path: /test
name: nfspvc
capacity:
storage: 200Gi
logSpec:
type: splunk
host: 10.11.12.13
index: main
username: elastic
passwordSecretName: es-elastic-user
scaleMetric: concurrency
state: enabled
31 changes: 12 additions & 19 deletions config/crd/bases/rcs.dana.io_capps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7642,11 +7642,6 @@ spec:
logSpec:
description: LogSpec defines the configuration for shipping Capp logs.
properties:
hecTokenSecretName:
description: |-
HecTokenSecretName defines the name of the secret
containing the Splunk Hec token.
type: string
host:
description: Host defines Elasticsearch or Splunk host.
type: string
Expand All @@ -7658,16 +7653,14 @@ spec:
PasswordSecretName defines the name of the secret
containing the password for authentication.
type: string
sslVerify:
description: SSLVerify determines whether to skip ssl verification.
type: boolean
type:
description: |-
Type defines where to send the Capp logs
Possible values : "elastic" and "splunk".
default: elastic
description: Type defines where to send the Capp logs
enum:
- elastic
type: string
username:
description: UserName defines a User for authentication.
description: User defines a User for authentication.
type: string
type: object
routeSpec:
Expand Down Expand Up @@ -8165,7 +8158,7 @@ spec:
properties:
conditions:
description: Conditions contain details about the current state
of the Output and Flow used by the Capp.
of the SyslogNGFlow and SyslogNGOutput used by the Capp.
items:
description: "Condition contains details for one aspect of the
current state of this API Resource.\n---\nThis struct is intended
Expand Down Expand Up @@ -8236,9 +8229,9 @@ spec:
- type
type: object
type: array
flow:
description: Flow represents the Status of the Flow used by the
Capp.
syslogngflow:
description: SyslogNGFlow represents the Status of the SyslogNGFlow
used by the Capp.
properties:
active:
type: boolean
Expand All @@ -8249,9 +8242,9 @@ spec:
problemsCount:
type: integer
type: object
output:
description: Output represents the Status of the Output used by
the Capp.
syslogngoutput:
description: SyslogNGOutput represents the Status of the SyslogNGOutput
used by the Capp.
properties:
active:
type: boolean
Expand Down
6 changes: 6 additions & 0 deletions config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
resources:
- manager.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
images:
- name: controller
newName: controller
newTag: latest
4 changes: 2 additions & 2 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ rules:
- apiGroups:
- logging.banzaicloud.io
resources:
- flows
- syslogngflows
verbs:
- create
- delete
Expand All @@ -64,7 +64,7 @@ rules:
- apiGroups:
- logging.banzaicloud.io
resources:
- outputs
- syslogngoutputs
verbs:
- create
- delete
Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ require (
github.com/dana-team/nfspvc-operator v0.2.2
github.com/go-logr/logr v1.4.1
github.com/go-logr/zapr v1.3.0
github.com/kube-logging/logging-operator/pkg/sdk v0.11.0
github.com/kube-logging/logging-operator/pkg/sdk v0.11.1-0.20240314152935-421fefebc813
github.com/onsi/ginkgo/v2 v2.17.1
github.com/onsi/gomega v1.31.1
github.com/openshift/api v0.0.0-20240410141538-3c0461467316
github.com/stretchr/testify v1.8.4
github.com/stretchr/testify v1.9.0
go.elastic.co/ecszap v1.0.2
go.uber.org/zap v1.27.0
golang.org/x/net v0.24.0
Expand All @@ -29,7 +29,7 @@ require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/blendle/zapdriver v1.3.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
Expand Down Expand Up @@ -57,8 +57,8 @@ require (
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.68.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.72.0 // indirect
github.com/prometheus/client_golang v1.19.0 // indirect
github.com/prometheus/client_model v0.6.0 // indirect
github.com/prometheus/common v0.52.2 // indirect
Expand Down
18 changes: 10 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
github.com/dana-team/nfspvc-operator v0.2.2 h1:/FwVD34O39ky9lQyOiVsyv8Et7K0Wkai6kseDThmR2o=
github.com/dana-team/nfspvc-operator v0.2.2/go.mod h1:l4J/LPQPf2ksPDZJu3RO3k4srKnXJ3fCS3JG0XTYZ5o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/emicklei/go-restful/v3 v3.11.0 h1:rAQeMHw1c7zTmncogyy8VvRZwtkmkZ4FxERmMY4rD+g=
github.com/emicklei/go-restful/v3 v3.11.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
github.com/evanphx/json-patch v5.6.0+incompatible h1:jBYDEEiFBPxA0v50tFdvOzQQTCvpL6mnFh5mB2/l16U=
Expand Down Expand Up @@ -99,8 +100,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kube-logging/logging-operator/pkg/sdk v0.11.0 h1:3yg+fdk6LnS+wVThEOr85qTtTKmS+6e5DrCtG1j6yFA=
github.com/kube-logging/logging-operator/pkg/sdk v0.11.0/go.mod h1:dWCUhDTFiW5V21LQJ2hoFzqZb1y6U1mFQU7ZXzd9tFE=
github.com/kube-logging/logging-operator/pkg/sdk v0.11.1-0.20240314152935-421fefebc813 h1:OMV8NhQGJYD2XQe5V1elb6USyp7XwdugCUIc34+o8G4=
github.com/kube-logging/logging-operator/pkg/sdk v0.11.1-0.20240314152935-421fefebc813/go.mod h1:KyAHHsYc1nA6ImWIYYZwqlw8KlalpHCwjOUqd+iv8N8=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
Expand All @@ -125,10 +126,11 @@ github.com/openshift/api v0.0.0-20240410141538-3c0461467316/go.mod h1:CxgbWAlvu2
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.68.0 h1:yl9ceUSUBo9woQIO+8eoWpcxZkdZgm89g+rVvu37TUw=
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.68.0/go.mod h1:9Uuu3pEU2jB8PwuqkHvegQ0HV/BlZRJUyfTYAqfdVF8=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.72.0 h1:9h7PxMhT1S8lOdadEKJnBh3ELMdO60XkoDV98grYjuM=
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.72.0/go.mod h1:4FiLCL664L4dNGeqZewiiD0NS7hhqi/CxyM4UOq5dfM=
github.com/prometheus/client_golang v1.19.0 h1:ygXvpU1AoN1MhdzckN+PyD9QJOSD4x7kmXYlnfbA6JU=
github.com/prometheus/client_golang v1.19.0/go.mod h1:ZRM9uEAypZakd+q/x7+gmsvXdURP+DABIEIjnmDdp+k=
github.com/prometheus/client_model v0.6.0 h1:k1v3CzpSRUTrKMppY35TLwPvxHqBu0bYgxZzqGIgaos=
Expand Down Expand Up @@ -156,8 +158,8 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
Expand Down
32 changes: 23 additions & 9 deletions internal/controllers/capp_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package controllers
import (
"context"
"fmt"
loggingv1beta1 "github.com/kube-logging/logging-operator/pkg/sdk/logging/api/v1beta1"
"time"

"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -46,8 +47,8 @@ type CappReconciler struct {
// +kubebuilder:rbac:groups=serving.knative.dev,resources=services,verbs=get;list;watch;update;create;delete
// +kubebuilder:rbac:groups=serving.knative.dev,resources=domainmappings,verbs=get;list;watch;update;create;delete
// +kubebuilder:rbac:groups=serving.knative.dev,resources=revisions,verbs=get;list;watch;update;create
// +kubebuilder:rbac:groups=logging.banzaicloud.io,resources=flows,verbs=get;list;watch;update;create;delete
// +kubebuilder:rbac:groups=logging.banzaicloud.io,resources=outputs,verbs=get;list;watch;update;create;delete
// +kubebuilder:rbac:groups=logging.banzaicloud.io,resources=syslogngflows,verbs=get;list;watch;update;create;delete
// +kubebuilder:rbac:groups=logging.banzaicloud.io,resources=syslogngoutputs,verbs=get;list;watch;update;create;delete
// +kubebuilder:rbac:groups=route.openshift.io,resources=routes,verbs=get;list;watch;update;create
// +kubebuilder:rbac:groups="",resources=nodes,verbs=get;list;watch;
// +kubebuilder:rbac:groups="",resources=secrets,verbs=get;list;watch;
Expand All @@ -62,22 +63,32 @@ func (r *CappReconciler) SetupWithManager(mgr ctrl.Manager) error {
For(&cappv1alpha1.Capp{}).
Watches(
&knativev1.Service{},
handler.EnqueueRequestsFromMapFunc(r.findCappFromKnative),
handler.EnqueueRequestsFromMapFunc(r.findCappFromEvent),
builder.WithPredicates(predicate.ResourceVersionChangedPredicate{}),
).
Watches(
&knativev1beta1.DomainMapping{},
handler.EnqueueRequestsFromMapFunc(r.findCappFromDomainMapping),
builder.WithPredicates(predicate.ResourceVersionChangedPredicate{}),
).
Watches(
&loggingv1beta1.SyslogNGOutput{},
handler.EnqueueRequestsFromMapFunc(r.findCappFromEvent),
builder.WithPredicates(predicate.ResourceVersionChangedPredicate{}),
).
Watches(
&loggingv1beta1.SyslogNGFlow{},
handler.EnqueueRequestsFromMapFunc(r.findCappFromEvent),
builder.WithPredicates(predicate.ResourceVersionChangedPredicate{}),
).
Complete(r)
}

// findCappFromKnative maps Knative reconciliation requests to Capp reconciliation requests.
func (r *CappReconciler) findCappFromKnative(ctx context.Context, knativeService client.Object) []reconcile.Request {
// findCappFromKnative maps reconciliation requests to Capp reconciliation requests.
func (r *CappReconciler) findCappFromEvent(ctx context.Context, object client.Object) []reconcile.Request {
request := reconcile.Request{NamespacedName: types.NamespacedName{
Namespace: knativeService.GetNamespace(),
Name: knativeService.GetName()}}
Namespace: object.GetNamespace(),
Name: object.GetName()}}

return []reconcile.Request{request}
}
Expand Down Expand Up @@ -108,21 +119,24 @@ func (r *CappReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
resourceManagers := map[string]rmanagers.ResourceManager{
rmanagers.DomainMapping: rmanagers.KnativeDomainMappingManager{Ctx: ctx, Log: logger, K8sclient: r.Client, EventRecorder: r.EventRecorder},
rmanagers.KnativeServing: rmanagers.KnativeServiceManager{Ctx: ctx, Log: logger, K8sclient: r.Client, EventRecorder: r.EventRecorder},
rmanagers.Flow: rmanagers.FlowManager{Ctx: ctx, Log: logger, K8sclient: r.Client, EventRecorder: r.EventRecorder},
rmanagers.Output: rmanagers.OutputManager{Ctx: ctx, Log: logger, K8sclient: r.Client, EventRecorder: r.EventRecorder},
rmanagers.SyslogNGFlow: rmanagers.SyslogNGFlowManager{Ctx: ctx, Log: logger, K8sclient: r.Client, EventRecorder: r.EventRecorder},
rmanagers.SyslogNGOutput: rmanagers.SyslogNGOutputManager{Ctx: ctx, Log: logger, K8sclient: r.Client, EventRecorder: r.EventRecorder},
rmanagers.NFSPVC: rmanagers.NFSPVCManager{Ctx: ctx, Log: logger, K8sclient: r.Client, EventRecorder: r.EventRecorder},
}

err, deleted := finalizer.HandleResourceDeletion(ctx, capp, r.Client, resourceManagers)
if err != nil {
return ctrl.Result{}, fmt.Errorf("failed to handle Capp deletion: %s", err.Error())
}

if deleted {
return ctrl.Result{}, nil
}

if err := finalizer.EnsureFinalizer(ctx, capp, r.Client); err != nil {
return ctrl.Result{}, fmt.Errorf("failed to ensure finalizer in Capp: %s", err.Error())
}

if err := r.SyncApplication(ctx, capp, resourceManagers, logger); err != nil {
if errors.IsConflict(err) {
logger.Info(fmt.Sprintf("Conflict detected requeuing: %s", err.Error()))
Expand Down
Loading

0 comments on commit e105680

Please sign in to comment.