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

setting statuses, and triggering reconciliation #17

Merged
merged 16 commits into from
Feb 1, 2024
Merged
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
4 changes: 2 additions & 2 deletions .github/workflows/artifacts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ jobs:
uses: docker/build-push-action@2eb1c1961a95fc15694676618e422e8ba1d63825 # v4.1.1
with:
context: .
platforms: linux/amd64,linux/arm64,linux/arm/v7
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
outputs: ${{ steps.build-output.outputs.value }},name=target,annotation-index.org.opencontainers.image.description=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.description'] }}
outputs: ${{ steps.build-output.outputs.value }},name=target
# push: ${{ inputs.publish }}

- name: Set image ref
Expand Down
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ linters:
- ineffassign
- lll
- misspell
- nakedret
- prealloc
- staticcheck
- typecheck
Expand Down
4 changes: 2 additions & 2 deletions api/telemetry/v1alpha1/collector_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type CollectorSpec struct {

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

//+kubebuilder:object:root=true
Expand All @@ -43,7 +43,7 @@ type Collector struct {
Status CollectorStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true
// +kubebuilder:object:root=true

// CollectorList contains a list of Collector
type CollectorList struct {
Expand Down
16 changes: 5 additions & 11 deletions api/telemetry/v1alpha1/subscription_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,20 @@ 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.

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

Outputs []NamespacedName `json:"outputs,omitempty"`
OTTL string `json:"ottl,omitempty"`
}

// SubscriptionStatus defines the observed state of Subscription
type SubscriptionStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
Tenant string `json:"tenant,omitempty"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
//+kubebuilder:printcolumn:name="Tenant",type=string,JSONPath=`.status.tenant`

// Subscription is the Schema for the subscriptions API
type Subscription struct {
Expand All @@ -48,7 +42,7 @@ type Subscription struct {
Status SubscriptionStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true
// +kubebuilder:object:root=true

// SubscriptionList contains a list of Subscription
type SubscriptionList struct {
Expand Down
8 changes: 5 additions & 3 deletions api/telemetry/v1alpha1/tenant_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,17 @@ type TenantSpec struct {

// TenantStatus defines the observed state of Tenant
type TenantStatus struct {
Subscriptions []string `json:"subscriptions"`
LogSourceNamespaces []string `json:"logSourceNamespaces"`
Subscriptions []string `json:"subscriptions,omitempty"`
LogSourceNamespaces []string `json:"logSourceNamespaces,omitempty"`
Collector string `json:"collector"`
OverOrion marked this conversation as resolved.
Show resolved Hide resolved
}

//+kubebuilder:object:root=true
//+kubebuilder:resource:scope=Cluster
//+kubebuilder:subresource:status
//+kubebuilder:printcolumn:name="Subscriptions",type=string,JSONPath=`.status.subscriptions`
//+kubebuilder:printcolumn:name="Logsource namespaces",type=string,JSONPath=`.status.logSourceNamespaces`
//+kubebuilder:printcolumn:name="Collector",type=string,JSONPath=`.status.collector`

// Tenant is the Schema for the tenants API
type Tenant struct {
Expand All @@ -45,7 +47,7 @@ type Tenant struct {
Status TenantStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true
// +kubebuilder:object:root=true

// TenantList contains a list of Tenant
type TenantList struct {
Expand Down
10 changes: 6 additions & 4 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log/zap"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"

rbacv1 "k8s.io/api/rbac/v1"

telemetryv1alpha1 "github.com/kube-logging/subscription-operator/api/telemetry/v1alpha1"
controller "github.com/kube-logging/subscription-operator/internal/controller/telemetry"
rbacv1 "k8s.io/api/rbac/v1"

//+kubebuilder:scaffold:imports
// +kubebuilder:scaffold:imports

otelv1alpha1 "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1"
)
Expand All @@ -51,7 +52,7 @@ func init() {

utilruntime.Must(rbacv1.AddToScheme(scheme))
utilruntime.Must(telemetryv1alpha1.AddToScheme(scheme))
//+kubebuilder:scaffold:scheme
// +kubebuilder:scaffold:scheme
}

func main() {
Expand All @@ -77,6 +78,7 @@ func main() {
HealthProbeBindAddress: probeAddr,
LeaderElection: enableLeaderElection,
LeaderElectionID: "87a80094.kube-logging.dev",

// LeaderElectionReleaseOnCancel defines if the leader should step down voluntarily
// when the Manager ends. This requires the binary to immediately end when the
// Manager is stopped, otherwise, this setting is unsafe. Setting this significantly
Expand All @@ -101,7 +103,7 @@ func main() {
setupLog.Error(err, "unable to create controller", "controller", "Collector")
os.Exit(1)
}
//+kubebuilder:scaffold:builder
// +kubebuilder:scaffold:builder

if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
setupLog.Error(err, "unable to set up health check")
Expand Down
2 changes: 0 additions & 2 deletions config/crd/bases/telemetry.kube-logging.dev_collectors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ spec:
items:
type: string
type: array
required:
- tenants
type: object
type: object
served: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ spec:
singular: subscription
scope: Namespaced
versions:
- name: v1alpha1
- additionalPrinterColumns:
- jsonPath: .status.tenant
name: Tenant
type: string
name: v1alpha1
schema:
openAPIV3Schema:
description: Subscription is the Schema for the subscriptions API
Expand Down Expand Up @@ -56,6 +60,9 @@ spec:
type: object
status:
description: SubscriptionStatus defines the observed state of Subscription
properties:
tenant:
type: string
type: object
type: object
served: true
Expand Down
8 changes: 6 additions & 2 deletions config/crd/bases/telemetry.kube-logging.dev_tenants.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ spec:
- jsonPath: .status.logSourceNamespaces
name: Logsource namespaces
type: string
- jsonPath: .status.collector
name: Collector
type: string
name: v1alpha1
schema:
openAPIV3Schema:
Expand Down Expand Up @@ -148,6 +151,8 @@ spec:
status:
description: TenantStatus defines the observed state of Tenant
properties:
collector:
type: string
logSourceNamespaces:
items:
type: string
Expand All @@ -157,8 +162,7 @@ spec:
type: string
type: array
required:
- logSourceNamespaces
- subscriptions
- collector
type: object
type: object
served: true
Expand Down
110 changes: 110 additions & 0 deletions docs/examples/two_tenants_one_subscription_each.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
apiVersion: v1
kind: Namespace
metadata:
name: collector
---
apiVersion: v1
kind: Namespace
metadata:
labels:
nsSelector: example-tenant-1
name: example-tenant-ns-1
---
apiVersion: v1
kind: Namespace
metadata:
labels:
nsSelector: example-tenant-2
name: example-tenant-ns-2
---
apiVersion: telemetry.kube-logging.dev/v1alpha1
kind: Collector
metadata:
name: example-collector-1
spec:
controlNamespace: collector
tenantSelector:
matchLabels:
collectorLabel: example-collector-1
---
apiVersion: telemetry.kube-logging.dev/v1alpha1
kind: Collector
metadata:
name: example-collector-2
spec:
controlNamespace: collector
tenantSelector:
matchLabels:
collectorLabel: example-collector-2
---
apiVersion: telemetry.kube-logging.dev/v1alpha1
kind: Tenant
metadata:
labels:
collectorLabel: example-collector-1
name: example-tenant-1
spec:
subscriptionNamespaceSelectors:
- matchLabels:
nsSelector: example-tenant-1
logSourceNamespaceSelectors:
- matchLabels:
nsSelector: example-tenant-1
---
apiVersion: telemetry.kube-logging.dev/v1alpha1
kind: Tenant
metadata:
labels:
collectorLabel: example-collector-2
name: example-tenant-2
spec:
subscriptionNamespaceSelectors:
- matchLabels:
nsSelector: example-tenant-2
logSourceNamespaceSelectors:
- matchLabels:
nsSelector: example-tenant-2
---
apiVersion: telemetry.kube-logging.dev/v1alpha1
kind: Subscription
metadata:
name: subscription-sample-1
namespace: example-tenant-ns-1
spec:
ottl: 'route()'
outputs:
- name: otlp-test-output-1
namespace: collector
---
apiVersion: telemetry.kube-logging.dev/v1alpha1
kind: Subscription
metadata:
name: subscription-sample-2
namespace: example-tenant-ns-2
spec:
ottl: 'route()'
outputs:
- name: otlp-test-output-2
namespace: collector
---
apiVersion: telemetry.kube-logging.dev/v1alpha1
kind: OtelOutput
metadata:
name: otlp-test-output-1
namespace: collector
spec:
otlp:
endpoint: receiver-collector.example-tenant-ns.svc.cluster.local:4317
tls:
insecure: true
---
apiVersion: telemetry.kube-logging.dev/v1alpha1
kind: OtelOutput
metadata:
name: otlp-test-output-2
namespace: collector
spec:
otlp:
endpoint: receiver-collector.example-tenant-ns.svc.cluster.local:4317
tls:
insecure: true
Loading
Loading