-
Notifications
You must be signed in to change notification settings - Fork 143
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
[RS-2297] Run dashboard-installer
on operator update
#3759
Changes from all commits
5947b1e
84b6f1e
0272721
de29769
baf8ba0
a0f1ae7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright (c) 2024 Tigera, Inc. All rights reserved. | ||
// Copyright (c) 2024-2025 Tigera, Inc. All rights reserved. | ||
|
||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
|
@@ -41,6 +41,7 @@ import ( | |
"github.com/tigera/operator/pkg/render/logstorage" | ||
"github.com/tigera/operator/pkg/render/logstorage/kibana" | ||
"github.com/tigera/operator/pkg/tls/certificatemanagement" | ||
"github.com/tigera/operator/version" | ||
) | ||
|
||
var ( | ||
|
@@ -49,6 +50,18 @@ var ( | |
PolicyName = networkpolicy.TigeraComponentPolicyPrefix + Name | ||
) | ||
|
||
// GetJobName makes a unique job name per operator version. | ||
// For dev images it takes the first 32 chars. | ||
func GetJobName() string { | ||
operatorVersion := strings.ReplaceAll(version.VERSION, ".", "-") | ||
|
||
if len(operatorVersion) >= 32 { | ||
operatorVersion = operatorVersion[:32] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is "32" in this context? Why do we need to truncate? I think we should have a comment explaining why we do this - it's not obvious! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think without truncation the job name ended up being 80+ characters and I think Job names are limited to 63. Good idea to explain in a comment. Maybe I can also include an example in the comment, for example: |
||
} | ||
|
||
return fmt.Sprintf("dashboards-installer-%s", operatorVersion) | ||
} | ||
|
||
func Dashboards(c *Config) render.Component { | ||
return &dashboards{ | ||
cfg: c, | ||
|
@@ -169,7 +182,7 @@ func (d *dashboards) AllowTigeraPolicy() *v3.NetworkPolicy { | |
Spec: v3.NetworkPolicySpec{ | ||
Order: &networkpolicy.HighPrecedenceOrder, | ||
Tier: networkpolicy.TigeraComponentTierName, | ||
Selector: fmt.Sprintf("job-name == '%s'", Name), | ||
Selector: fmt.Sprintf("job-name contains '%s'", Name), | ||
Types: []v3.PolicyType{v3.PolicyTypeEgress}, | ||
Egress: egressRules, | ||
}, | ||
|
@@ -261,7 +274,7 @@ func (d *dashboards) Job() *batchv1.Job { | |
|
||
podTemplate := relasticsearch.DecorateAnnotations(&corev1.PodTemplateSpec{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Labels: map[string]string{"job-name": Name, "k8s-app": Name}, | ||
Labels: map[string]string{"job-name": GetJobName(), "k8s-app": GetJobName()}, | ||
Annotations: annotations, | ||
}, | ||
Spec: corev1.PodSpec{ | ||
|
@@ -288,13 +301,13 @@ func (d *dashboards) Job() *batchv1.Job { | |
job := &batchv1.Job{ | ||
TypeMeta: metav1.TypeMeta{Kind: "Job", APIVersion: "batch/v1"}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: Name, | ||
Name: GetJobName(), | ||
Namespace: d.cfg.Namespace, | ||
}, | ||
Spec: batchv1.JobSpec{ | ||
Selector: &metav1.LabelSelector{ | ||
MatchLabels: map[string]string{ | ||
"job-name": Name, | ||
"job-name": GetJobName(), | ||
}, | ||
}, | ||
Template: *podTemplate, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
"spec": { | ||
"order": 1, | ||
"tier": "allow-tigera", | ||
"selector": "job-name == 'dashboards-installer'", | ||
"selector": "job-name contains 'dashboards-installer'", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should be using a different selector rather than the "contains" operator here. There's no reason we need to use the My concern is just that |
||
"types": [ | ||
"Egress" | ||
], | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're switching to this, we should stop exporting the
Name
variable so that nobody accidentally uses the wrong value.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
Name
isn't actually used except for within this function, we should probably just scope it to this function to be extra sure (i.e., remove the package level variable)