Skip to content
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
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
COPY pkg/tracing/go.mod pkg/tracing/go.sum ./pkg/tracing/
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download
Expand All @@ -30,6 +31,7 @@ RUN go mod download
COPY cmd/main.go cmd/main.go
COPY api/ api/
COPY internal/ internal/
COPY pkg/ pkg/

# Build
# the GOARCH has not a default value to allow the binary be built according to the host where the command
Expand Down
2 changes: 2 additions & 0 deletions Dockerfile.agent
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ ARG TARGETARCH
WORKDIR /workspace

COPY go.mod go.sum ./
COPY pkg/tracing/go.mod pkg/tracing/go.sum ./pkg/tracing/
RUN go mod download

COPY cmd/validation-agent/ cmd/validation-agent/
COPY internal/ internal/
COPY api/ api/
COPY pkg/ pkg/

RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} \
go build -a -o validation-agent cmd/validation-agent/main.go
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,13 @@ vet: ## Run go vet against code.
go vet ./...

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

.PHONY: test-tracing
test-tracing: ## Run tracing package tests.
cd pkg/tracing && go test ./...

.PHONY: lint
lint: golangci-lint ## Run golangci-lint linter
$(GOLANGCI_LINT) run
Expand Down
9 changes: 9 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,13 @@ resources:
kind: ModelValidation
path: github.com/sigstore/model-validation-operator/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: sigstore.dev
group: ml
kind: TelemetryConfig
path: github.com/sigstore/model-validation-operator/api/v1alpha1
version: v1alpha1
version: "3"
118 changes: 118 additions & 0 deletions api/v1alpha1/telemetryconfig_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// Copyright 2025 The Sigstore 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 (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// TracingConfig defines the OpenTelemetry tracing configuration to inject
// into validation agent containers.
type TracingConfig struct {
// Enabled controls whether tracing env vars are injected into matched containers.
// +kubebuilder:default=true
Enabled bool `json:"enabled"`

// Endpoint is the OTLP collector endpoint (sets OTEL_EXPORTER_OTLP_ENDPOINT).
// For example, "http://otel-collector.monitoring:4317".
// +kubebuilder:validation:Required
Endpoint string `json:"endpoint"`

// Insecure controls whether the gRPC connection to the collector uses TLS.
// Defaults to true, which is typical for in-cluster collectors.
// Sets OTEL_EXPORTER_OTLP_INSECURE.
// +kubebuilder:default=true
// +kubebuilder:validation:Optional
Insecure *bool `json:"insecure,omitempty"`

// Sampler specifies the trace sampler to use (sets OTEL_TRACES_SAMPLER).
// +kubebuilder:validation:Optional
// +kubebuilder:validation:Enum=always_on;always_off;traceidratio;parentbased_always_on;parentbased_always_off;parentbased_traceidratio

Check failure on line 43 in api/v1alpha1/telemetryconfig_types.go

View workflow job for this annotation

GitHub Actions / Run Linting

The line is 136 characters long, which exceeds the maximum of 120 characters. (lll)
Sampler string `json:"sampler,omitempty"`

// SamplerArg is the argument for the sampler (sets OTEL_TRACES_SAMPLER_ARG).
// For example, "0.1" for a 10% sampling ratio with traceidratio.
// +kubebuilder:validation:Optional
SamplerArg string `json:"samplerArg,omitempty"`

// Env specifies additional environment variables to inject.
// This allows setting any OTEL_* variable without requiring CRD changes.
// +kubebuilder:validation:Optional
Env []corev1.EnvVar `json:"env,omitempty"`
}

// TelemetryConfigSpec defines the desired state of TelemetryConfig.
type TelemetryConfigSpec struct {
// NamespaceSelector selects namespaces this config applies to.
// An empty or nil selector matches all namespaces.
// +kubebuilder:validation:Optional
NamespaceSelector *metav1.LabelSelector `json:"namespaceSelector,omitempty"`

// Selector selects which ModelValidation CRs this config applies to.
// An empty or nil selector matches all ModelValidation CRs.
// +kubebuilder:validation:Optional
Selector *metav1.LabelSelector `json:"selector,omitempty"`

// Tracing defines the OpenTelemetry tracing configuration.
Tracing TracingConfig `json:"tracing"`
}

// TelemetryConfigStatus defines the observed state of TelemetryConfig.
type TelemetryConfigStatus struct {
// MatchedNamespaceCount is the number of namespaces matched by namespaceSelector.
MatchedNamespaceCount int32 `json:"matchedNamespaceCount"`

// MatchedModelValidationCount is the number of ModelValidation CRs matched by selector.
MatchedModelValidationCount int32 `json:"matchedModelValidationCount"`

// LastApplied is the timestamp when this config was last evaluated.
LastApplied metav1.Time `json:"lastApplied,omitempty"`

// Conditions represent the latest available observations of the TelemetryConfig's state.
Conditions []metav1.Condition `json:"conditions,omitempty"`
}

// TelemetryConfig is the Schema for the telemetryconfigs API.
// It defines OpenTelemetry configuration that the operator injects into
// validation agent containers via environment variables.
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:shortName=tc
// +kubebuilder:printcolumn:name="Endpoint",type=string,JSONPath=`.spec.tracing.endpoint`
// +kubebuilder:printcolumn:name="Sampler",type=string,JSONPath=`.spec.tracing.sampler`
// +kubebuilder:printcolumn:name="Matched NS",type=integer,JSONPath=`.status.matchedNamespaceCount`
// +kubebuilder:printcolumn:name="Matched MV",type=integer,JSONPath=`.status.matchedModelValidationCount`
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
type TelemetryConfig struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec TelemetryConfigSpec `json:"spec,omitempty"`
Status TelemetryConfigStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&TelemetryConfig{}, &TelemetryConfigList{})
}
135 changes: 135 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

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

9 changes: 9 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,15 @@ func main() {
os.Exit(1)
}

tcReconciler := &controller.TelemetryConfigReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}
if err := tcReconciler.SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create TelemetryConfig controller")
os.Exit(1)
}

setupLog.Info("starting manager")
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
setupLog.Error(err, "problem running manager")
Expand Down
Loading
Loading