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

Unset (default) images in TempoStack CR #675

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
18 changes: 18 additions & 0 deletions .chloggen/unset_images_in_cr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: breaking

# The name of the component, or a single word describing the area of concern, (e.g. operator, github action)
component: operator

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Unset (default) images in TempoStack CR

# One or more tracking issues related to the change
issues: [674]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext: |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would document here the workaround

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which workaround?

This upgrade reverts any change to the `spec.images` fields of any TempoStack instance.
Beginning with version 0.6.0, the image location is not stored in the TempoStack instance unless it is changed manually.
25 changes: 0 additions & 25 deletions apis/tempo/v1alpha1/tempostack_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,31 +74,6 @@ func (d *Defaulter) Default(ctx context.Context, obj runtime.Object) error {
}
r.Labels["tempo.grafana.com/distribution"] = d.ctrlConfig.Distribution

if r.Spec.Images.Tempo == "" {
if d.ctrlConfig.DefaultImages.Tempo == "" {
return fmt.Errorf("please specify a tempo image in the CR or in the %s env var", v1alpha1.EnvRelatedImageTempo)
}
r.Spec.Images.Tempo = d.ctrlConfig.DefaultImages.Tempo
}
if r.Spec.Images.TempoQuery == "" {
if d.ctrlConfig.DefaultImages.TempoQuery == "" {
return fmt.Errorf("please specify a tempoQuery image in the CR or in the %s env var", v1alpha1.EnvRelatedImageTempoQuery)
}
r.Spec.Images.TempoQuery = d.ctrlConfig.DefaultImages.TempoQuery
}
if r.Spec.Images.TempoGateway == "" {
if d.ctrlConfig.DefaultImages.TempoGateway == "" {
return fmt.Errorf("please specify a tempoGateway image in the CR or in the %s env var", v1alpha1.EnvRelatedImageTempoGateway)
}
r.Spec.Images.TempoGateway = d.ctrlConfig.DefaultImages.TempoGateway
}
if r.Spec.Images.TempoGatewayOpa == "" {
if d.ctrlConfig.DefaultImages.TempoGatewayOpa == "" {
return fmt.Errorf("please specify a tempoGatewayOpa image in the CR or in the %s env var", v1alpha1.EnvRelatedImageTempoGatewayOpa)
}
r.Spec.Images.TempoGatewayOpa = d.ctrlConfig.DefaultImages.TempoGatewayOpa
}

if r.Spec.ServiceAccount == "" {
r.Spec.ServiceAccount = naming.DefaultServiceAccountName(r.Name)
}
Expand Down
18 changes: 4 additions & 14 deletions apis/tempo/v1alpha1/tempostack_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,8 @@ func TestDefault(t *testing.T) {
},
Spec: TempoStackSpec{
ReplicationFactor: 1,
Images: v1alpha1.ImagesSpec{
Tempo: "docker.io/grafana/tempo:x.y.z",
TempoQuery: "docker.io/grafana/tempo-query:x.y.z",
TempoGateway: "docker.io/observatorium/gateway:1.2.3",
TempoGatewayOpa: "docker.io/observatorium/opa-openshift:1.2.3",
},
ServiceAccount: "tempo-test",
Images: v1alpha1.ImagesSpec{},
ServiceAccount: "tempo-test",
Retention: RetentionSpec{
Global: RetentionConfig{
Traces: metav1.Duration{Duration: 48 * time.Hour},
Expand Down Expand Up @@ -201,13 +196,8 @@ func TestDefault(t *testing.T) {
},
Spec: TempoStackSpec{
ReplicationFactor: 1,
Images: v1alpha1.ImagesSpec{
Tempo: "docker.io/grafana/tempo:x.y.z",
TempoQuery: "docker.io/grafana/tempo-query:x.y.z",
TempoGateway: "docker.io/observatorium/gateway:1.2.3",
TempoGatewayOpa: "docker.io/observatorium/opa-openshift:1.2.3",
},
ServiceAccount: "tempo-test",
Images: v1alpha1.ImagesSpec{},
ServiceAccount: "tempo-test",
Retention: RetentionSpec{
Global: RetentionConfig{
Traces: metav1.Duration{Duration: 48 * time.Hour},
Expand Down
20 changes: 12 additions & 8 deletions cmd/generate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"

configv1alpha1 "github.com/grafana/tempo-operator/apis/config/v1alpha1"
"github.com/grafana/tempo-operator/apis/tempo/v1alpha1"
"github.com/grafana/tempo-operator/cmd"
controllers "github.com/grafana/tempo-operator/controllers/tempo"
Expand All @@ -41,9 +40,9 @@ func loadSpec(r io.Reader) (v1alpha1.TempoStack, error) {
return spec, nil
}

func build(ctrlConfig configv1alpha1.ProjectConfig, params manifestutils.Params) ([]client.Object, error) {
func build(params manifestutils.Params) ([]client.Object, error) {
// apply default values from Defaulter webhook
defaulterWebhook := v1alpha1.NewDefaulter(ctrlConfig)
defaulterWebhook := v1alpha1.NewDefaulter(params.CtrlConfig)
err := defaulterWebhook.Default(context.Background(), &params.Tempo)
if err != nil {
return nil, err
Expand Down Expand Up @@ -105,7 +104,7 @@ func toYAMLManifest(scheme *runtime.Scheme, objects []client.Object, out io.Writ

func generate(c *cobra.Command, crPath string, outPath string, params manifestutils.Params) error {
rootCmdConfig := c.Context().Value(cmd.RootConfigKey{}).(cmd.RootConfig)
ctrlConfig, options := rootCmdConfig.CtrlConfig, rootCmdConfig.Options
options := rootCmdConfig.Options

var specReader io.Reader
if crPath == "/dev/stdin" {
Expand All @@ -132,7 +131,7 @@ func generate(c *cobra.Command, crPath string, outPath string, params manifestut
}

params.Tempo = spec
objects, err := build(ctrlConfig, params)
objects, err := build(params)
if err != nil {
return fmt.Errorf("error building manifests: %w", err)
}
Expand Down Expand Up @@ -170,12 +169,16 @@ func NewGenerateCommand() *cobra.Command {
var gcsBucket string
var s3Endpoint string
var s3Bucket string
params := manifestutils.Params{}

cmd := &cobra.Command{
Use: "generate",
Short: "Generate YAML manifests from a Tempo CR",
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(c *cobra.Command, args []string) error {
rootCmdConfig := c.Context().Value(cmd.RootConfigKey{}).(cmd.RootConfig)
params := manifestutils.Params{
CtrlConfig: rootCmdConfig.CtrlConfig,
}

switch {
case azureContainer != "":
params.StorageParams.AzureStorage = controllers.GetAzureParams(v1alpha1.TempoStack{}, &corev1.Secret{Data: map[string][]byte{
Expand All @@ -191,7 +194,8 @@ func NewGenerateCommand() *cobra.Command {
"bucket": []byte(s3Bucket),
}})
}
return generate(cmd, crPath, outPath, params)

return generate(c, crPath, outPath, params)
},
}
cmd.Flags().StringVar(&crPath, "cr", "/dev/stdin", "Input CR")
Expand Down
18 changes: 9 additions & 9 deletions cmd/generate/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@ import (
)

func TestBuild(t *testing.T) {
ctrlConfig := configv1alpha1.ProjectConfig{
DefaultImages: configv1alpha1.ImagesSpec{
Tempo: "tempo-image",
TempoQuery: "tempo-query-image",
TempoGateway: "tempo-gateway-image",
TempoGatewayOpa: "tempo-gateway-opa-image",
},
}
params := manifestutils.Params{
CtrlConfig: configv1alpha1.ProjectConfig{
DefaultImages: configv1alpha1.ImagesSpec{
Tempo: "tempo-image",
TempoQuery: "tempo-query-image",
TempoGateway: "tempo-gateway-image",
TempoGatewayOpa: "tempo-gateway-opa-image",
},
},
StorageParams: manifestutils.StorageParams{
AzureStorage: &manifestutils.AzureStorage{},
GCS: &manifestutils.GCS{},
S3: &manifestutils.S3{},
},
}

objects, err := build(ctrlConfig, params)
objects, err := build(params)
require.NoError(t, err)
require.Equal(t, 14, len(objects))
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/tempo/tempostack_create_or_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (r *TempoStackReconciler) createOrUpdate(ctx context.Context, log logr.Logg
managedObjects, err := manifests.BuildAll(manifestutils.Params{
Tempo: tempo,
StorageParams: storageConfig,
Gates: r.CtrlConfig.Gates,
CtrlConfig: r.CtrlConfig,
TLSProfile: tlsProfile,
GatewayTenantSecret: tenantSecrets,
GatewayTenantsData: gatewayTenantsData,
Expand Down
10 changes: 7 additions & 3 deletions internal/manifests/compactor/compactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func BuildCompactor(params manifestutils.Params) ([]client.Object, error) {
if err != nil {
return nil, err
}
gates := params.Gates
gates := params.CtrlConfig.Gates
tempo := params.Tempo
if gates.HTTPEncryption || gates.GRPCEncryption {
caBundleName := naming.SigningCABundleName(tempo.Name)
Expand All @@ -45,6 +45,10 @@ func deployment(params manifestutils.Params) (*v1.Deployment, error) {
labels := manifestutils.ComponentLabels(manifestutils.CompactorComponentName, tempo.Name)
annotations := manifestutils.CommonAnnotations(params.ConfigChecksum)
cfg := tempo.Spec.Template.Compactor
image := tempo.Spec.Images.Tempo
if image == "" {
image = params.CtrlConfig.DefaultImages.Tempo
}

d := &v1.Deployment{
TypeMeta: metav1.TypeMeta{
Expand All @@ -71,7 +75,7 @@ func deployment(params manifestutils.Params) (*v1.Deployment, error) {
Containers: []corev1.Container{
{
Name: "tempo",
Image: tempo.Spec.Images.Tempo,
Image: image,
Args: []string{
"-target=compactor",
"-config.file=/conf/tempo.yaml",
Expand All @@ -89,7 +93,7 @@ func deployment(params manifestutils.Params) (*v1.Deployment, error) {
Protocol: corev1.ProtocolTCP,
},
},
ReadinessProbe: manifestutils.TempoReadinessProbe(params.Gates.HTTPEncryption),
ReadinessProbe: manifestutils.TempoReadinessProbe(params.CtrlConfig.Gates.HTTPEncryption),
VolumeMounts: []corev1.VolumeMount{
{
Name: manifestutils.ConfigVolumeName,
Expand Down
12 changes: 6 additions & 6 deletions internal/manifests/config/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func fromRateLimitSpecToRateLimitOptionsMap(ratemaps map[string]v1alpha1.RateLim

func buildQueryFrontEndConfig(params manifestutils.Params) ([]byte, error) {
if !params.Tempo.Spec.Template.Gateway.Enabled {
params.Gates.HTTPEncryption = false
params.CtrlConfig.Gates.HTTPEncryption = false
}

return buildConfiguration(params)
Expand All @@ -58,7 +58,7 @@ func buildConfiguration(params manifestutils.Params) ([]byte, error) {
tlsopts := tlsOptions{}
var err error

if params.Gates.GRPCEncryption || params.Gates.HTTPEncryption {
if params.CtrlConfig.Gates.GRPCEncryption || params.CtrlConfig.Gates.HTTPEncryption {
tlsopts, err = buildTLSConfig(params)
if err != nil {
return []byte{}, err
Expand All @@ -79,8 +79,8 @@ func buildConfiguration(params manifestutils.Params) ([]byte, error) {
Multitenancy: tempo.Spec.Tenants != nil,
Gateway: tempo.Spec.Template.Gateway.Enabled,
Gates: featureGates{
GRPCEncryption: params.Gates.GRPCEncryption,
HTTPEncryption: params.Gates.HTTPEncryption,
GRPCEncryption: params.CtrlConfig.Gates.GRPCEncryption,
HTTPEncryption: params.CtrlConfig.Gates.HTTPEncryption,
},
TLS: tlsopts,
ReceiverTLS: buildReceiverTLSConfig(tempo),
Expand Down Expand Up @@ -151,8 +151,8 @@ func buildTempoQueryConfig(params manifestutils.Params) ([]byte, error) {
TLS: tlsopts,
HTTPPort: manifestutils.PortHTTPServer,
Gates: featureGates{
GRPCEncryption: params.Gates.GRPCEncryption,
HTTPEncryption: params.Gates.HTTPEncryption,
GRPCEncryption: params.CtrlConfig.Gates.GRPCEncryption,
HTTPEncryption: params.CtrlConfig.Gates.HTTPEncryption,
},
TenantHeader: manifestutils.TenantHeader,
Gateway: params.Tempo.Spec.Template.Gateway.Enabled,
Expand Down
16 changes: 10 additions & 6 deletions internal/manifests/config/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1644,9 +1644,11 @@ ingester_client:
},
},
TLSProfile: tc.options,
Gates: configv1alpha1.FeatureGates{
HTTPEncryption: true,
GRPCEncryption: true,
CtrlConfig: configv1alpha1.ProjectConfig{
Gates: configv1alpha1.FeatureGates{
HTTPEncryption: true,
GRPCEncryption: true,
},
},
})
require.NoError(t, err)
Expand Down Expand Up @@ -1803,9 +1805,11 @@ ingester_client:
"TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384"},
MinTLSVersion: "VersionTLS12",
},
Gates: configv1alpha1.FeatureGates{
HTTPEncryption: true,
GRPCEncryption: true,
CtrlConfig: configv1alpha1.ProjectConfig{
Gates: configv1alpha1.FeatureGates{
HTTPEncryption: true,
GRPCEncryption: true,
},
},
})
require.NoError(t, err)
Expand Down
10 changes: 7 additions & 3 deletions internal/manifests/distributor/distributor.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func BuildDistributor(params manifestutils.Params) ([]client.Object, error) {
if err != nil {
return nil, err
}
gates := params.Gates
gates := params.CtrlConfig.Gates
tempo := params.Tempo
if gates.HTTPEncryption || gates.GRPCEncryption {
caBundleName := naming.SigningCABundleName(tempo.Name)
Expand Down Expand Up @@ -125,6 +125,10 @@ func deployment(params manifestutils.Params) *v1.Deployment {
labels := manifestutils.ComponentLabels(manifestutils.DistributorComponentName, tempo.Name)
annotations := manifestutils.CommonAnnotations(params.ConfigChecksum)
cfg := tempo.Spec.Template.Distributor
image := tempo.Spec.Images.Tempo
if image == "" {
image = params.CtrlConfig.DefaultImages.Tempo
}

containerPorts := []corev1.ContainerPort{
{
Expand Down Expand Up @@ -207,14 +211,14 @@ func deployment(params manifestutils.Params) *v1.Deployment {
Containers: []corev1.Container{
{
Name: "tempo",
Image: tempo.Spec.Images.Tempo,
Image: image,
Args: []string{
"-target=distributor",
"-config.file=/conf/tempo.yaml",
"-log.level=info",
},
Ports: containerPorts,
ReadinessProbe: manifestutils.TempoReadinessProbe(params.Gates.HTTPEncryption),
ReadinessProbe: manifestutils.TempoReadinessProbe(params.CtrlConfig.Gates.HTTPEncryption),
VolumeMounts: []corev1.VolumeMount{
{
Name: manifestutils.ConfigVolumeName,
Expand Down
Loading
Loading