Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: output visibility #137

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions api/telemetry/v1alpha1/collector_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package v1alpha1
import (
"time"

"github.com/kube-logging/telemetry-controller/internal/controller/telemetry/resources/state"
otelv1beta1 "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -93,8 +94,8 @@ func (c CollectorSpec) GetMemoryLimit() *resource.Quantity {

// CollectorStatus defines the observed state of Collector
type CollectorStatus struct {
Tenants []string `json:"tenants,omitempty"`
State State `json:"state,omitempty"`
Tenants []string `json:"tenants,omitempty"`
State state.State `json:"state,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down
7 changes: 0 additions & 7 deletions api/telemetry/v1alpha1/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@

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
32 changes: 31 additions & 1 deletion api/telemetry/v1alpha1/output_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package v1alpha1

import (
"github.com/kube-logging/telemetry-controller/internal/controller/telemetry/resources"
"github.com/kube-logging/telemetry-controller/internal/controller/telemetry/resources/state"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down Expand Up @@ -105,7 +107,7 @@ type Endpoint struct {
// Controls whether to validate the tcp address.
// Turning this ON may result in the collector failing to start if it came up faster then the endpoint.
// default is false.
ValidateTCPResolution bool `json:"validate_tcp_resolution"`
ValidateTCPResolution bool `json:"validate_tcp_resolution,omitempty"`
}

type KubernetesMetadata struct {
Expand Down Expand Up @@ -155,10 +157,30 @@ type Fluentforward struct {

// OutputStatus defines the observed state of Output
type OutputStatus struct {
Tenant string `json:"tenant,omitempty"`
State state.State `json:"state,omitempty"`
}

func (o *Output) GetTenant() string {
return o.Status.Tenant
}

func (o *Output) SetTenant(tenant string) {
o.Status.Tenant = tenant
}

func (o *Output) GetState() state.State {
return o.Status.State
}

func (o *Output) SetState(state state.State) {
o.Status.State = state
}

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

// Output is the Schema for the outputs API
Expand All @@ -179,6 +201,14 @@ type OutputList struct {
Items []Output `json:"items"`
}

func (l *OutputList) GetItems() []resources.ResourceOwnedByTenant {
items := make([]resources.ResourceOwnedByTenant, len(l.Items))
for i := range l.Items {
items[i] = &l.Items[i]
}
return items
}

func init() {
SchemeBuilder.Register(&Output{}, &OutputList{})
}
Expand Down
29 changes: 28 additions & 1 deletion api/telemetry/v1alpha1/subscription_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package v1alpha1

import (
"github.com/kube-logging/telemetry-controller/internal/controller/telemetry/resources"
"github.com/kube-logging/telemetry-controller/internal/controller/telemetry/resources/state"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -28,14 +30,31 @@ type SubscriptionSpec struct {
// +kubebuilder:validation:Required

// The outputs to which the logs will be routed if the condition evaluates to true.
// Outputs must be in the same namespace as the subscription to be valid.
Outputs []NamespacedName `json:"outputs"`
}

// SubscriptionStatus defines the observed state of Subscription
type SubscriptionStatus struct {
Tenant string `json:"tenant,omitempty"`
Outputs []NamespacedName `json:"outputs,omitempty"`
State State `json:"state,omitempty"`
State state.State `json:"state,omitempty"`
}

func (s *Subscription) GetTenant() string {
return s.Status.Tenant
}

func (s *Subscription) SetTenant(tenant string) {
s.Status.Tenant = tenant
}

func (s *Subscription) GetState() state.State {
return s.Status.State
}

func (s *Subscription) SetState(state state.State) {
s.Status.State = state
}

// +kubebuilder:object:root=true
Expand Down Expand Up @@ -63,6 +82,14 @@ type SubscriptionList struct {
Items []Subscription `json:"items"`
}

func (l *SubscriptionList) GetItems() []resources.ResourceOwnedByTenant {
items := make([]resources.ResourceOwnedByTenant, len(l.Items))
for i := range l.Items {
items[i] = &l.Items[i]
}
return items
}

func init() {
SchemeBuilder.Register(&Subscription{}, &SubscriptionList{})
}
Expand Down
5 changes: 3 additions & 2 deletions api/telemetry/v1alpha1/tenant_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package v1alpha1

import (
"github.com/kube-logging/telemetry-controller/internal/controller/telemetry/resources/state"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -86,7 +87,7 @@ type PersistenceConfig struct {

// TenantSpec defines the desired state of Tenant
type TenantSpec struct {
// Determines the namespaces from which subscriptions are collected by this tenant.
// Determines the namespaces from which subscriptions and outputs are collected by this tenant.
SubscriptionNamespaceSelectors []metav1.LabelSelector `json:"subscriptionNamespaceSelectors,omitempty"`

// Determines the namespaces from which logs are collected by this tenant.
Expand All @@ -106,7 +107,7 @@ type TenantStatus struct {
Subscriptions []NamespacedName `json:"subscriptions,omitempty"`
LogSourceNamespaces []string `json:"logSourceNamespaces,omitempty"`
ConnectedBridges []string `json:"connectedBridges,omitempty"`
State State `json:"state,omitempty"`
State state.State `json:"state,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ spec:
singular: output
scope: Namespaced
versions:
- name: v1alpha1
- additionalPrinterColumns:
- jsonPath: .status.tenant
name: Tenant
type: string
- jsonPath: .status.state
name: State
type: string
name: v1alpha1
schema:
openAPIV3Schema:
description: Output is the Schema for the outputs API
Expand Down Expand Up @@ -164,7 +171,6 @@ spec:
type: boolean
required:
- tcp_addr
- validate_tcp_resolution
type: object
kubernetes_metadata:
properties:
Expand Down Expand Up @@ -698,6 +704,11 @@ spec:
type: object
status:
description: OutputStatus defines the observed state of Output
properties:
state:
type: string
tenant:
type: string
type: object
type: object
served: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ spec:
telemetry to the outputs.
type: string
outputs:
description: The outputs to which the logs will be routed if the condition
evaluates to true.
description: |-
The outputs to which the logs will be routed if the condition evaluates to true.
Outputs must be in the same namespace as the subscription to be valid.
items:
properties:
name:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ spec:
Cannot be used together with LogSourceNamespaceSelectors.
type: boolean
subscriptionNamespaceSelectors:
description: Determines the namespaces from which subscriptions are
collected by this tenant.
description: Determines the namespaces from which subscriptions and
outputs are collected by this tenant.
items:
description: |-
A label selector is a label query over a set of resources. The result of matchLabels and
Expand Down
15 changes: 13 additions & 2 deletions config/crd/bases/telemetry.kube-logging.dev_outputs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ spec:
singular: output
scope: Namespaced
versions:
- name: v1alpha1
- additionalPrinterColumns:
- jsonPath: .status.tenant
name: Tenant
type: string
- jsonPath: .status.state
name: State
type: string
name: v1alpha1
schema:
openAPIV3Schema:
description: Output is the Schema for the outputs API
Expand Down Expand Up @@ -164,7 +171,6 @@ spec:
type: boolean
required:
- tcp_addr
- validate_tcp_resolution
type: object
kubernetes_metadata:
properties:
Expand Down Expand Up @@ -698,6 +704,11 @@ spec:
type: object
status:
description: OutputStatus defines the observed state of Output
properties:
state:
type: string
tenant:
type: string
type: object
type: object
served: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ spec:
telemetry to the outputs.
type: string
outputs:
description: The outputs to which the logs will be routed if the condition
evaluates to true.
description: |-
The outputs to which the logs will be routed if the condition evaluates to true.
Outputs must be in the same namespace as the subscription to be valid.
items:
properties:
name:
Expand Down
4 changes: 2 additions & 2 deletions config/crd/bases/telemetry.kube-logging.dev_tenants.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ spec:
Cannot be used together with LogSourceNamespaceSelectors.
type: boolean
subscriptionNamespaceSelectors:
description: Determines the namespaces from which subscriptions are
collected by this tenant.
description: Determines the namespaces from which subscriptions and
outputs are collected by this tenant.
items:
description: |-
A label selector is a label query over a set of resources. The result of matchLabels and
Expand Down
25 changes: 16 additions & 9 deletions docs/demos/loki/manifests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,19 @@ spec:
apiVersion: telemetry.kube-logging.dev/v1alpha1
kind: Output
metadata:
name: loki
namespace: collector
name: loki-1
namespace: tenant-demo-1
spec:
otlphttp:
endpoint: http://loki.loki.svc.cluster.local:3100/otlp/
tls:
insecure: true
---
apiVersion: telemetry.kube-logging.dev/v1alpha1
kind: Output
metadata:
name: loki-2
namespace: tenant-demo-2
spec:
otlphttp:
endpoint: http://loki.loki.svc.cluster.local:3100/otlp/
Expand Down Expand Up @@ -62,9 +73,7 @@ spec:
condition: "true"
outputs:
- name: loki
namespace: collector
- name: openobserve-1
namespace: collector
namespace: tenant-demo-1
---
apiVersion: telemetry.kube-logging.dev/v1alpha1
kind: Tenant
Expand All @@ -88,7 +97,5 @@ metadata:
spec:
condition: "true"
outputs:
- name: loki
namespace: collector
- name: openobserve-2
namespace: collector
- name: loki-2
namespace: tenant-demo-2
15 changes: 2 additions & 13 deletions docs/demos/openobserve/demo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,13 @@ spec:
condition: "true"
outputs:
- name: otlp-openobserve
namespace: collector
---
apiVersion: telemetry.kube-logging.dev/v1alpha1
kind: Subscription
metadata:
name: subscription-sample-2
namespace: example-tenant-ns
spec:
condition: "true"
outputs:
- name: otlp-openobserve
namespace: collector
namespace: example-tenant-ns
---
apiVersion: telemetry.kube-logging.dev/v1alpha1
kind: Output
metadata:
name: otlp-openobserve
namespace: collector
namespace: example-tenant-ns
spec:
otlp:
endpoint: openobserve-otlp-grpc.openobserve.svc.cluster.local:5081
Expand Down
3 changes: 2 additions & 1 deletion docs/examples/fluent-forward/telemetry-controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ metadata:
namespace: default
spec:
fluentforward:
endpoint: all-to-file-fluentd.default:24240
endpoint:
tcp_addr: all-to-file-fluentd.default:24240
tag: otelcol
kubernetes_metadata:
key: kubernetes
Expand Down
Loading
Loading