Skip to content

Commit

Permalink
Operator upgraded to latest SDK (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
EldarAliiev authored Jun 28, 2022
1 parent e832fdb commit 735bb28
Show file tree
Hide file tree
Showing 23 changed files with 130 additions and 831 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ bin

# Test binary, build with `go test -c`
*.test
preflight.log
artifacts/

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ endif
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)

# Image URL to use all building/pushing image targets
IMG ?= "registry.connect.redhat.com/coralogix/coralogix-operator:1.0.0"
IMG ?= registry.connect.redhat.com/coralogix/coralogix-operator:$(VERSION)
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd"

Expand Down
4 changes: 1 addition & 3 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ projectName: coralogix-operator
repo: github.com/coralogix/coralogix-operator
resources:
-
# TODO(user): Uncomment the below line if this resource implements a controller, else delete it.
# controller: true
controller: true
domain: coralogix.com
group: loggers
kind: CoralogixLogger
# TODO(user): Update the package path for your API if the below value is incorrect.
path: github.com/coralogix/coralogix-operator/api/v1
version: v1
version: "3"
Expand Down
15 changes: 13 additions & 2 deletions api/v1/coralogixlogger_types.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020 Coralogix Ltd..
Copyright 2022 Coralogix Ltd..
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -28,16 +28,27 @@ type CoralogixLoggerSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

// Coralogix Region
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Region"
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:select:Europe","urn:alm:descriptor:com.tectonic.ui:select:Europe2","urn:alm:descriptor:com.tectonic.ui:select:India","urn:alm:descriptor:com.tectonic.ui:select:Singapore","urn:alm:descriptor:com.tectonic.ui:select:US"}
// +kubebuilder:validation:Enum=Europe;Europe2;India;Singapore;US
// +kubebuilder:default:=Europe
// +kubebuilder:validation:Optional
Region string `json:"region"`
// Coralogix Private Key
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Private Key"
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors="urn:alm:descriptor:com.tectonic.ui:password"
// +kubebuilder:validation:Format="password"
// +kubebuilder:validation:Pattern="^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-z]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
// +kubebuilder:validation:MinLength=36
// +kubebuilder:validation:MaxLength=36
// +kubebuilder:validation:Required
PrivateKey string `json:"private_key"`
// Current cluster name
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Cluster Name",xDescriptors="urn:alm:descriptor:com.tectonic.ui:advanced"
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Cluster Name"
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors="urn:alm:descriptor:com.tectonic.ui:advanced"
// +kubebuilder:default:=cluster.local
// +kubebuilder:validation:Optional
ClusterName string `json:"cluster_name"`
}

Expand Down
2 changes: 1 addition & 1 deletion bundle.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LABEL operators.operatorframework.io.bundle.manifests.v1=manifests/
LABEL operators.operatorframework.io.bundle.metadata.v1=metadata/
LABEL operators.operatorframework.io.bundle.package.v1=coralogix-operator
LABEL operators.operatorframework.io.bundle.channels.v1=alpha
LABEL operators.operatorframework.io.metrics.builder=operator-sdk-unknown
LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.21.0
LABEL operators.operatorframework.io.metrics.mediatype.v1=metrics+v1
LABEL operators.operatorframework.io.metrics.project_layout=go.kubebuilder.io/v2

Expand Down
24 changes: 18 additions & 6 deletions bundle/manifests/coralogix-operator.clusterserviceversion.yaml

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion bundle/manifests/loggers.coralogix.com_coralogixloggers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ spec:
description: CoralogixLoggerSpec defines the desired state of CoralogixLogger
properties:
cluster_name:
default: cluster.local
description: Current cluster name
type: string
private_key:
Expand All @@ -44,8 +45,17 @@ spec:
minLength: 36
pattern: ^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-z]{4}-[0-9a-f]{4}-[0-9a-f]{12}$
type: string
region:
default: Europe
description: Coralogix Region
enum:
- Europe
- Europe2
- India
- Singapore
- US
type: string
required:
- cluster_name
- private_key
type: object
status:
Expand Down
5 changes: 4 additions & 1 deletion bundle/metadata/annotations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ annotations:
operators.operatorframework.io.bundle.metadata.v1: metadata/
operators.operatorframework.io.bundle.package.v1: coralogix-operator
operators.operatorframework.io.bundle.channels.v1: alpha
operators.operatorframework.io.metrics.builder: operator-sdk-unknown
operators.operatorframework.io.metrics.builder: operator-sdk-v1.21.0
operators.operatorframework.io.metrics.mediatype.v1: metrics+v1
operators.operatorframework.io.metrics.project_layout: go.kubebuilder.io/v2

# Annotations for testing.
operators.operatorframework.io.test.mediatype.v1: scorecard+v1
operators.operatorframework.io.test.config.v1: tests/scorecard/

# OpenShift annotations.
com.redhat.openshift.versions: v4.6-v4.9
12 changes: 11 additions & 1 deletion config/crd/bases/loggers.coralogix.com_coralogixloggers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ spec:
description: CoralogixLoggerSpec defines the desired state of CoralogixLogger
properties:
cluster_name:
default: cluster.local
description: Current cluster name
type: string
private_key:
Expand All @@ -45,8 +46,17 @@ spec:
minLength: 36
pattern: ^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-z]{4}-[0-9a-f]{4}-[0-9a-f]{12}$
type: string
region:
default: Europe
description: Coralogix Region
enum:
- Europe
- Europe2
- India
- Singapore
- US
type: string
required:
- cluster_name
- private_key
type: object
status:
Expand Down
2 changes: 1 addition & 1 deletion config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ kind: Kustomization
images:
- name: controller
newName: registry.connect.redhat.com/coralogix/coralogix-operator
newTag: 1.0.0
newTag: 1.0.1

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions config/samples/loggers_v1_coralogixlogger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ kind: CoralogixLogger
metadata:
name: coralogix-logger
spec:
region: Europe
private_key: 00000000-0000-0000-0000-000000000000
cluster_name: cluster.local
17 changes: 16 additions & 1 deletion controllers/coralogixlogger_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,17 @@ func newClusterRoleBinding(cr *loggersv1.CoralogixLogger) *rbacv1.ClusterRoleBin
func newDaemonSet(cr *loggersv1.CoralogixLogger) *appsv1.DaemonSet {
var uid int64 = 0
var privileged bool = true
coralogixEndpoints := map[string]string{
"Europe": "api.coralogix.com",
"Europe2": "api.eu2.coralogix.com",
"India": "api.app.coralogix.in",
"Singapore": "api.coralogixsg.com",
"US": "api.coralogix.us",
}
coralogixURL, ok := coralogixEndpoints[cr.Spec.Region]
if !ok {
coralogixURL = "api.coralogix.com"
}
return &appsv1.DaemonSet{
TypeMeta: metav1.TypeMeta{
Kind: "DaemonSet",
Expand Down Expand Up @@ -359,13 +370,17 @@ func newDaemonSet(cr *loggersv1.CoralogixLogger) *appsv1.DaemonSet {
Spec: corev1.PodSpec{
Containers: []corev1.Container{{
Name: "fluentd",
Image: "registry.connect.redhat.com/coralogix/coralogix-fluentd:1.0.0",
Image: "registry.connect.redhat.com/coralogix/coralogix-fluentd:1.0.1",
ImagePullPolicy: corev1.PullAlways,
SecurityContext: &corev1.SecurityContext{
RunAsUser: &uid,
Privileged: &privileged,
},
Env: []corev1.EnvVar{
{
Name: "CORALOGIX_ENDPOINT",
Value: coralogixURL,
},
{
Name: "CORALOGIX_PRIVATE_KEY",
Value: cr.Spec.PrivateKey,
Expand Down
7 changes: 3 additions & 4 deletions internal/build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ LABEL name="coralogix-fluentd" \
description="Special FluentD image for Coralogix integration"

RUN yum install -y hostname sudo make gcc gcc-c++ ruby-devel && \
curl -L https://toolbelt.treasuredata.com/sh/install-redhat-td-agent3.sh | sh && \
td-agent-gem install --no-rdoc --no-ri --no-document \
curl -L https://toolbelt.treasuredata.com/sh/install-redhat-td-agent4.sh | sh && \
td-agent-gem install \
fluent-plugin-kubernetes_metadata_filter \
fluent-plugin-multi-format-parser \
fluent-plugin-detect-exceptions \
fluent-plugin-coralogix && \
fluent-plugin-detect-exceptions && \
td-agent-gem sources --clear-all && \
rm -rf /tmp/* /var/tmp/* /var/cache/* /opt/td-agent/embedded/lib/ruby/gems/*/cache/*.gem && \
ulimit -n 65536 && \
Expand Down
42 changes: 36 additions & 6 deletions internal/configs/td-agent.conf
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,41 @@
</parse>
</filter>
<match *.containers.**>
@type coralogix
privatekey "#{ENV['CORALOGIX_PRIVATE_KEY']}"
appname "$kubernetes.namespace_name"
subsystemname "$kubernetes.container_name"
timestamp_key_name time
is_json true
@type relabel
@label @CORALOGIX
</match>
</label>
<label @CORALOGIX>
<filter **>
@type record_transformer
@log_level warn
enable_ruby true
auto_typecast true
renew_record true
<record>
privateKey "#{ENV['CORALOGIX_PRIVATE_KEY']}"
applicationName ${record.dig("kubernetes", "namespace_name")}
subsystemName ${record.dig("kubernetes", "container_name")}
computerName ${record.dig("kubernetes", "host")}
timestamp ${time.strftime('%s%L')}
text ${record.to_json}
</record>
</filter>
<match **>
@type http
@id out_http_coralogix
endpoint "https://#{ENV['CORALOGIX_ENDPOINT'] || 'api.coralogix.com'}/logs/rest/singles"
headers_from_placeholders {"private_key":"${$.privateKey}"}
error_response_as_unrecoverable false
<buffer $.privateKey>
@type memory
chunk_limit_size 10MB
compress gzip
flush_interval 1s
overflow_action block
retry_max_times 5
retry_type periodic
retry_wait 2
</buffer>
</match>
</label>

This file was deleted.

291 changes: 0 additions & 291 deletions packagemanifests/1.0.0/coralogix-operator.clusterserviceversion.yaml

This file was deleted.

83 changes: 0 additions & 83 deletions packagemanifests/1.0.0/loggers.coralogix.com_coralogixloggers.yaml

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 735bb28

Please sign in to comment.