Skip to content

Commit

Permalink
Completed a working alpha for the operator (#11)
Browse files Browse the repository at this point in the history
* Made the operator parse messages and create config map from it

* Created Logic top copying reference pod

* Deploy the log-output with flowtest

* Refactor the CRDs and the controller

* Implemented cleanUpResources

* Added coded to slice the flow

* added error status

* Fixed Flow deployment

* created the index checker

* Fixed few typos

* Flow send logs data to log-output pod

* controller update passed matches and clean up passing flows

* Fixed the issue with filter test

* Updated demo flow

* Fixed issues mentioned in the review
  • Loading branch information
isala404 authored Jul 12, 2021
1 parent adb03f2 commit 0de4dfe
Show file tree
Hide file tree
Showing 17 changed files with 1,653 additions and 971 deletions.
14 changes: 9 additions & 5 deletions operator/api/v1alpha1/flowtest_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,20 @@ type FlowTestSpec struct {

// FlowTestStatus defines the observed state of FlowTest
type FlowTestStatus struct {
FailedMatch flowv1beta1.Match `json:"failedMatch"`
FailedFilter flowv1beta1.Filter `json:"failedFilter"`
// +kubebuilder:validation:Enum=Created;Running;Completed
// +nullable
FailedMatches []flowv1beta1.Match `json:"failedMatches"`
// +nullable
FailedFilters []flowv1beta1.Filter `json:"failedFilters"`
// +kubebuilder:default:="Created"
// +kubebuilder:validation:Enum=Created;Running;Completed;Error
Status FlowStatus `json:"status"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
// +kubebuilder:printcolumn:JSONPath=".status.simulationPod.name",name="SimulationPod",type="string"
// +kubebuilder:printcolumn:JSONPath=".status.simulationFlow.name",name="SimulationFlow",type="string"
// +kubebuilder:printcolumn:JSONPath=".spec.referencePod.name",name="Reference Pod",type="string"
// +kubebuilder:printcolumn:JSONPath=".spec.referenceFlow.name",name="Reference Flow",type="string"
// +kubebuilder:printcolumn:JSONPath=".status.status",name="Status",type="string"

// FlowTest is the Schema for the flowtests API
type FlowTest struct {
Expand Down
9 changes: 4 additions & 5 deletions operator/api/v1alpha1/reference_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ type ReferenceObject struct {
type FlowStatus string

const (
Created FlowStatus = "Created"
Running FlowStatus = "Running"
Skipped FlowStatus = "Skipped"
Failed FlowStatus = "Failed"
Passed FlowStatus = "Passed"
Created FlowStatus = "Created"
Running FlowStatus = "Running"
Completed FlowStatus = "Completed"
Error FlowStatus = "Error"
)
17 changes: 15 additions & 2 deletions operator/api/v1alpha1/zz_generated.deepcopy.go

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

1,866 changes: 943 additions & 923 deletions operator/config/crd/bases/loggingplumber.isala.me_flowtests.yaml

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions operator/config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ generatorOptions:
disableNameSuffixHash: true

configMapGenerator:
- name: manager-config
files:
- files:
- controller_manager_config.yaml
name: manager-config
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
images:
- name: controller
newName: controller
newTag: latest
12 changes: 12 additions & 0 deletions operator/config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ metadata:
creationTimestamp: null
name: manager-role
rules:
- apiGroups:
- logging.banzaicloud.io
resources:
- clusterflows
- clusteroutputs
- flows
- outputs
verbs:
- create
- delete
- get
- list
- apiGroups:
- loggingplumber.isala.me
resources:
Expand Down
13 changes: 9 additions & 4 deletions operator/config/samples/loggingplumber_v1alpha1_flowtest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@ apiVersion: loggingplumber.isala.me/v1alpha1
kind: FlowTest
metadata:
name: flowtest-sample
labels:
app.kubernetes.io/name: pod-simulation
app.kubernetes.io/managed-by: rancher-logging-explorer
app.kubernetes.io/created-by: logging-plumber
loggingplumber.isala.me/flowtest: flowtest-sample
spec:
referencePod:
kind: Pod
name: test-pod
name: busybox-echo
namespace: default
referenceFlow:
kind: ClusterFlow
name: all-logs
kind: Flow
name: busybox-echo
namespace: default
sentMessages:
- "[2021-06-10T11:50:06Z] @DEBUG Tam ipsae consuetudo infelix adtendi contexo mansuefecisti diutius re. 1373 ::0.403911"
- "[2021-06-10T11:50:07Z] @WARNING Ne hi flagitantur alienam neglecta. 1374 ::0.474177"
- "[2021-06-10T11:50:08Z] @INFO Amo ideoque die se at, caro aer, ad cor. 1375 ::0.263548"
- "[2021-06-10T11:50:09Z] @INFO Se contexo servis inpiis erogo, diligit ita significaret eosdem. 1376 ::0.405282"
- "[2021-06-10T11:50:09Z] @INFO Se contexo servis inpiis erogo, diligit ita significaret eosdem. 1376 ::0.405282"
68 changes: 68 additions & 0 deletions operator/config/samples/simulations.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
apiVersion: v1
kind: Pod
metadata:
name: busybox-echo
labels:
loggingplumber.isala.me/test: simulations
spec:
containers:
- name: busybox
image: busybox
command: ["sh", "-c", "x=1; while [ $x -gt -1 ]; do echo \"{'count': '$(( x++ ))', 'date': '$(date)'}\" && sleep 5; done"]
---
apiVersion: logging.banzaicloud.io/v1beta1
kind: Flow
metadata:
name: busybox-echo
labels:
loggingplumber.isala.me/test: simulations
spec:
localOutputRefs:
- busybox-echo
match:
- select:
labels:
loggingplumber.isala.me/test: invalid
- select:
labels:
loggingplumber.isala.me/test: simulations
filters:
- record_modifier:
records:
- foo: "bar"
- grep:
regexp:
- key: first
pattern: /^5\d\d$/
---
apiVersion: logging.banzaicloud.io/v1beta1
kind: Output
metadata:
name: busybox-echo
labels:
loggingplumber.isala.me/test: simulations
spec:
http:
endpoint: "http://logging-plumber-log-aggregator.default.svc/busybox-echo/"
buffer:
flush_interval: 10s
flush_mode: interval
---
apiVersion: v1
kind: Service
metadata:
name: logging-plumber-log-aggregator
labels:
loggingplumber.isala.me/test: simulations
spec:
type: ClusterIP
ports:
- port: 80
targetPort: http
protocol: TCP
name: http
selector:
app.kubernetes.io/name: logging-plumber-log-aggregator
app.kubernetes.io/managed-by: rancher-logging-explorer
app.kubernetes.io/created-by: logging-plumber
loggingplumber.isala.me/component: log-aggregator
74 changes: 74 additions & 0 deletions operator/controllers/cleanup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package controllers

import (
"context"
"fmt"
flowv1beta1 "github.com/banzaicloud/logging-operator/pkg/sdk/api/v1beta1"
v1 "k8s.io/api/core/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"
)

func (r *FlowTestReconciler) cleanUpResources(ctx context.Context, flowTestName string) error {
logger := log.FromContext(ctx)

matchingLabels := &client.MatchingLabels{"loggingplumber.isala.me/flowtest": flowTestName}

var podList v1.PodList
if err := r.List(ctx, &podList, matchingLabels); client.IgnoreNotFound(err) != nil {
logger.Error(err, fmt.Sprintf("failed to get provisioned %s", podList.Kind))
return err
}

for _, resource := range podList.Items {
if err := r.Delete(ctx, &resource); client.IgnoreNotFound(err) != nil {
logger.Error(err, fmt.Sprintf("failed to delete a provisioned %s", resource.Kind), "uuid", resource.GetUID(), "name", resource.GetName())
return err
}
logger.V(1).Info(fmt.Sprintf("%s deleted", resource.Kind), "uuid", resource.GetUID(), "name", resource.GetName())
}

var configMapList v1.ConfigMapList
if err := r.List(ctx, &configMapList, matchingLabels); client.IgnoreNotFound(err) != nil {
logger.Error(err, fmt.Sprintf("failed to get provisioned %s", configMapList.Kind))
return err
}

for _, resource := range configMapList.Items {
if err := r.Delete(ctx, &resource); client.IgnoreNotFound(err) != nil {
logger.Error(err, fmt.Sprintf("failed to delete a provisioned %s", resource.Kind), "uuid", resource.GetUID(), "name", resource.GetName())
return err
}
logger.V(1).Info(fmt.Sprintf("%s deleted", resource.Kind), "uuid", resource.GetUID(), "name", resource.GetName())
}

var flows flowv1beta1.FlowList
if err := r.List(ctx, &flows, &client.MatchingLabels{"loggingplumber.isala.me/flowtest": flowTestName}); client.IgnoreNotFound(err) != nil {
logger.Error(err, fmt.Sprintf("failed to get provisioned %s", flows.Kind))
//return err
}

for _, resource := range flows.Items {
if err := r.Delete(ctx, &resource); client.IgnoreNotFound(err) != nil {
logger.Error(err, fmt.Sprintf("failed to delete a provisioned %s", resource.Kind), "uuid", resource.GetUID(), "name", resource.GetName())
return err
}
logger.V(1).Info(fmt.Sprintf("%s deleted", resource.Kind), "uuid", resource.GetUID(), "name", resource.GetName())
}

var outputs flowv1beta1.OutputList
if err := r.List(ctx, &outputs, &client.MatchingLabels{"loggingplumber.isala.me/flowtest": flowTestName}); client.IgnoreNotFound(err) != nil {
logger.Error(err, fmt.Sprintf("failed to get provisioned %s", outputs.Kind))
//return err
}

for _, resource := range outputs.Items {
if err := r.Delete(ctx, &resource); client.IgnoreNotFound(err) != nil {
logger.Error(err, fmt.Sprintf("failed to delete a provisioned %s", resource.Kind), "uuid", resource.GetUID(), "name", resource.GetName())
return err
}
logger.V(1).Info(fmt.Sprintf("%s deleted", resource.Kind), "uuid", resource.GetUID(), "name", resource.GetName())
}

return nil
}
Loading

0 comments on commit 0de4dfe

Please sign in to comment.