Skip to content

Commit

Permalink
Merge pull request #86 from kube-logging/feat/enable-tenant-routing
Browse files Browse the repository at this point in the history
feat: enable tenant routing
  • Loading branch information
csatib02 authored Oct 28, 2024
2 parents e687718 + 094701c commit 00a9177
Show file tree
Hide file tree
Showing 41 changed files with 1,650 additions and 222 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Binaries for programs and plugins
*.exe
*.exe~
Expand Down
77 changes: 38 additions & 39 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@

# Image URL to use all building/pushing image targets
BIN := ${PWD}/bin

export PATH := $(BIN):$(PATH)
Expand All @@ -14,7 +12,8 @@ KIND_CLUSTER ?= kind
CI_MODE_ENABLED := ""
NO_KIND_CLEANUP := ""

IMG ?= ghcr.io/kube-logging/telemetry-controller:0.0.11
# Image URL to use all building/pushing image targets
IMG ?= controller:local
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.28.0

Expand Down Expand Up @@ -80,8 +79,12 @@ fmt: ## Run go fmt against code.
vet: ## Run go vet against code.
go vet ./...

.PHONY: tidy
tidy: ## Tidy Go modules
find . -iname "go.mod" -not -path "./.devcontainer/*" | xargs -L1 sh -c 'cd $$(dirname $$0); go mod tidy'

.PHONY: test
test: manifests generate fmt vet envtest ## Run tests.
test: manifests generate fmt vet envtest ## Run verifications and tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test -v ./... -coverprofile cover.out

GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint
Expand All @@ -93,21 +96,49 @@ golangci-lint:
}

.PHONY: lint
lint: golangci-lint ## Run golangci-lint linter & yamllint
lint: golangci-lint ## Run golangci-lint
$(GOLANGCI_LINT) run

.PHONY: lint-fix
lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
lint-fix: golangci-lint ## Run golangci-lint and perform fixes
$(GOLANGCI_LINT) run --fix

.PHONY: run-delve
run-delve: generate fmt vet manifests
go build -o bin/manager cmd/main.go
dlv --listen=:2345 --headless=true --api-version=2 --accept-multiclient exec ./bin/manager

.PHONY: e2e-test
e2e-test: ## Run e2e tests
cd e2e && export CI_MODE=$(CI_MODE_ENABLED) NO_KIND_CLEANUP=$(NO_KIND_CLEANUP) && $(TIMEOUT_CMD) --foreground 15m ./e2e_test.sh || (echo "E2E test failed"; exit 1)

.PHONY: e2e-test-ci
e2e-test-ci: CI_MODE_ENABLED=1
e2e-test-ci: NO_KIND_CLEANUP=1
e2e-test-ci: IMG="controller:latest" ## Run e2e tests, telemetry collector runs inside k8s
e2e-test-ci: docker-build e2e-test

.PHONY: check-diff
check-diff: generate
git diff --exit-code

.PHONY: license-check
license-check: ${LICENSEI} .licensei.cache ## Run license check
${LICENSEI} check
${LICENSEI} header

.PHONY: license-cache
license-cache: ${LICENSEI} ## Generate license cache
${LICENSEI} cache

##@ Build

.PHONY: build
build: manifests generate fmt vet ## Build manager binary.
go build -o bin/manager cmd/main.go

.PHONY: run
run: manifests generate fmt vet ## Run a controller from your host.
run: manifests generate fmt vet ## Run the controller from your host.
go run ./cmd/main.go

# If you wish to build the manager image targeting other platforms you can use the --platform flag.
Expand Down Expand Up @@ -208,38 +239,6 @@ envtest: $(ENVTEST) crddir/github.com/open-telemetry/opentelemetry-operator ## D
$(ENVTEST): $(LOCALBIN)
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest

.PHONY: run-delve
run-delve: generate fmt vet manifests
go build -o bin/manager cmd/main.go
dlv --listen=:2345 --headless=true --api-version=2 --accept-multiclient exec ./bin/manager

.PHONY: tidy
tidy: ## Tidy Go modules
find . -iname "go.mod" -not -path "./.devcontainer/*" | xargs -L1 sh -c 'cd $$(dirname $$0); go mod tidy'

.PHONY: e2e-test
e2e-test: ## Run e2e tests
cd e2e && export CI_MODE=$(CI_MODE_ENABLED) NO_KIND_CLEANUP=$(NO_KIND_CLEANUP) && $(TIMEOUT_CMD) --foreground 15m ./e2e_test.sh || (echo "E2E test failed"; exit 1)

.PHONY: e2e-test-ci
e2e-test-ci: CI_MODE_ENABLED=1
e2e-test-ci: NO_KIND_CLEANUP=1
e2e-test-ci: IMG="controller:latest" ## Run e2e tests, telemetry collector runs inside k8s
e2e-test-ci: docker-build e2e-test

.PHONY: check-diff
check-diff: generate
git diff --exit-code

.PHONY: license-check
license-check: ${LICENSEI} .licensei.cache ## Run license check
${LICENSEI} check
${LICENSEI} header

.PHONY: license-cache
license-cache: ${LICENSEI} ## Generate license cache
${LICENSEI} cache

stern: | ${BIN}
GOBIN=${BIN} go install github.com/stern/stern@latest

Expand Down
9 changes: 7 additions & 2 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ repo: github.com/kube-logging/telemetry-controller
resources:
- api:
crdVersion: v1
namespaced: true
controller: true
domain: kube-logging.dev
group: telemetry
Expand All @@ -28,7 +27,6 @@ resources:
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
domain: kube-logging.dev
group: telemetry
kind: Tenant
Expand All @@ -42,4 +40,11 @@ resources:
kind: Output
path: github.com/kube-logging/telemetry-controller/api/telemetry/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
domain: kube-logging.dev
group: telemetry
kind: Bridge
path: github.com/kube-logging/telemetry-controller/api/telemetry/v1alpha1
version: v1alpha1
version: "3"
28 changes: 11 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Telemetry-controller can be configured using Custom Resources to set up an opini
To get started with the Telemetry Controller, complete the following steps. Alternatively, see our [Telemetry Controller overview and quickstart blog post](https://axoflow.com/reinvent-kubernetes-logging-with-telemetry-controller/).

### Prerequisites

- go version v1.22+
- docker version 24+
- kubectl version v1.26+
Expand All @@ -32,6 +33,7 @@ minikube start --container-runtime=containerd
### Deployment steps for users

Deploy latest telemetry-controller:

```sh
# Install telemetry-controller, and opentelemetry-operator as a sub-chart
helm upgrade --install --wait --create-namespace --namespace telemetry-controller-system telemetry-controller oci://ghcr.io/kube-logging/helm-charts/telemetry-controller
Expand Down Expand Up @@ -82,25 +84,30 @@ Open the UI at `localhost:5080`, navigate to the `Ingestion/OTEL Collector` tab,
![Openobserve auth](docs/assets/openobserve-auth.png)

Paste this token to the example manifests:

```sh
sed -i '' -e "s/\<TOKEN\>/INSERT YOUR COPIED TOKEN HERE/" docs/examples/simple-demo/one_tenant_two_subscriptions.yaml
```

```sh
# Deploy the pipeline definition
kubectl apply -f docs/examples/simple-demo/one_tenant_two_subscriptions.yaml
```

**Create a workload, which will generate logs for the pipeline:**
Create a workload, which will generate logs for the pipeline:

```sh
helm install --wait --create-namespace --namespace example-tenant-ns --generate-name oci://ghcr.io/kube-logging/helm-charts/log-generator
```

**Open the Openobserve UI and inspect the generated log messages**
Open the Openobserve UI and inspect the generated log messages:

Set up portforwarding for Openobserve UI

```sh
kubectl -n openobserve port-forward svc/openobserve 5080:5080
```

![Openobserve logs](docs/assets/openobserve-logs.png)

### Sending logs to logging-operator (example)
Expand Down Expand Up @@ -147,31 +154,18 @@ Apply the provided example resource for telemetry-controller: [telemetry-control
kubectl apply -f telemetry-controller.yaml
```


## Contributing

If you find this project useful, help us:

- Support the development of this project and star this repo! :star:
- Help new users with issues they may encounter :muscle:
- Send a pull request with your new features and bug fixes :rocket:
- Send a pull request with your new features and bug fixes :rocket:

Please read the [Organisation's Code of Conduct](https://github.com/kube-logging/.github/blob/main/CODE_OF_CONDUCT.md)!

*For more information, read our organization's [contribution guidelines](https://github.com/kube-logging/.github/blob/main/CONTRIBUTING.md)*.

## License

Copyright © 2024 Kube logging authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
The project is licensed under the [Apache 2.0 License](LICENSE).
62 changes: 62 additions & 0 deletions api/telemetry/v1alpha1/bridge_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright © 2024 Kube logging authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// BridgeSpec defines the desired state of Bridge
type BridgeSpec struct {
SourceTenant string `json:"sourceTenant,omitempty"`
TargetTenant string `json:"targetTenant,omitempty"`
// The OTTL condition which must be satisfied in order to forward telemetry
// from the source tenant to the target tenant
OTTL string `json:"ottl,omitempty"`
}

// BridgeStatus defines the observed state of Bridge
type BridgeStatus struct {
State State `json:"state,omitempty"`
}

//+kubebuilder:object:root=true
//+kubebuilder:resource:scope=Cluster,categories=telemetry-all
//+kubebuilder:subresource:status
//+kubebuilder:printcolumn:name="Source Tenant",type=string,JSONPath=`.spec.sourceTenant`
//+kubebuilder:printcolumn:name="Target Tenant",type=string,JSONPath=`.spec.targetTenant`
//+kubebuilder:printcolumn:name="State",type=string,JSONPath=`.status.state`

// Bridge is the Schema for the Bridges API
type Bridge struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec BridgeSpec `json:"spec,omitempty"`
Status BridgeStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// BridgeList contains a list of Bridge
type BridgeList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Bridge `json:"items"`
}

func init() {
SchemeBuilder.Register(&Bridge{}, &BridgeList{})
}
7 changes: 7 additions & 0 deletions api/telemetry/v1alpha1/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@

package v1alpha1

type State string

const (
StateReady State = "ready"
StateFailed State = "failed"
)

type NamespacedName struct {
Namespace string `json:"namespace"`
Name string `json:"name"`
Expand Down
6 changes: 0 additions & 6 deletions api/telemetry/v1alpha1/output_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,8 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// OutputSpec defines the desired state of Output
type OutputSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

OTLPGRPC *OTLPGRPC `json:"otlp,omitempty"`
Fluentforward *Fluentforward `json:"fluentforward,omitempty"`
OTLPHTTP *OTLPHTTP `json:"otlphttp,omitempty"`
Expand Down
2 changes: 2 additions & 0 deletions api/telemetry/v1alpha1/subscription_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ type SubscriptionSpec struct {
type SubscriptionStatus struct {
Tenant string `json:"tenant,omitempty"`
Outputs []NamespacedName `json:"outputs,omitempty"`
State State `json:"state,omitempty"`
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Tenant",type=string,JSONPath=`.status.tenant`
// +kubebuilder:printcolumn:name="Outputs",type=string,JSONPath=`.status.outputs`
// +kubebuilder:printcolumn:name="State",type=string,JSONPath=`.status.state`
// +kubebuilder:resource:categories=telemetry-all

// Subscription is the Schema for the subscriptions API
Expand Down
Loading

0 comments on commit 00a9177

Please sign in to comment.