mirror of
https://github.com/prometheus-operator/prometheus-operator.git
synced 2025-04-20 19:29:10 +00:00
pkg/prometheus: Set image with @sha256 prefix
This commit is contained in:
parent
b1d747bc85
commit
8e9bf6f035
2 changed files with 6 additions and 6 deletions
pkg/prometheus
|
@ -718,12 +718,12 @@ func makeStatefulSetSpec(p monitoringv1.Prometheus, c *Config, ruleConfigMapName
|
|||
// If the tag is specified, we use the tag to identify the container image.
|
||||
// If the sha is specified, we use the sha to identify the container image,
|
||||
// as it has even stronger immutable guarantees to identify the image.
|
||||
prometheusTag := p.Spec.Version
|
||||
prometheusImage := fmt.Sprintf("%s:%s", p.Spec.BaseImage, p.Spec.Version)
|
||||
if p.Spec.Tag != "" {
|
||||
prometheusTag = p.Spec.Tag
|
||||
prometheusImage = fmt.Sprintf("%s:%s", p.Spec.BaseImage, p.Spec.Tag)
|
||||
}
|
||||
if p.Spec.Sha != "" {
|
||||
prometheusTag = p.Spec.Sha
|
||||
prometheusImage = fmt.Sprintf("%s@sha256:%s", p.Spec.BaseImage, p.Spec.Sha)
|
||||
}
|
||||
|
||||
return &appsv1.StatefulSetSpec{
|
||||
|
@ -745,7 +745,7 @@ func makeStatefulSetSpec(p monitoringv1.Prometheus, c *Config, ruleConfigMapName
|
|||
Containers: append([]v1.Container{
|
||||
{
|
||||
Name: "prometheus",
|
||||
Image: fmt.Sprintf("%s:%s", p.Spec.BaseImage, prometheusTag),
|
||||
Image: prometheusImage,
|
||||
Ports: ports,
|
||||
Args: promArgs,
|
||||
VolumeMounts: promVolumeMounts,
|
||||
|
|
|
@ -380,7 +380,7 @@ func TestTagAndShaAndVersion(t *testing.T) {
|
|||
|
||||
sset, err = makeStatefulSet(monitoringv1.Prometheus{
|
||||
Spec: monitoringv1.PrometheusSpec{
|
||||
Sha: "1809f7cd0c75acf34f56d8c19782b99c6b5fcd14128a3cc79aca38a4f94af3ff",
|
||||
Sha: "7384a79f4b4991bf8269e7452390249b7c70bcdd10509c8c1c6c6e30e32fb324",
|
||||
Tag: "my-unrelated-tag",
|
||||
Version: "v2.3.2",
|
||||
},
|
||||
|
@ -390,7 +390,7 @@ func TestTagAndShaAndVersion(t *testing.T) {
|
|||
}
|
||||
|
||||
image = sset.Spec.Template.Spec.Containers[0].Image
|
||||
expected = "quay.io/prometheus/prometheus:1809f7cd0c75acf34f56d8c19782b99c6b5fcd14128a3cc79aca38a4f94af3ff"
|
||||
expected = "quay.io/prometheus/prometheus@sha256:7384a79f4b4991bf8269e7452390249b7c70bcdd10509c8c1c6c6e30e32fb324"
|
||||
if image != expected {
|
||||
t.Fatalf("Unexpected container image.\n\nExpected: %s\n\nGot: %s", expected, image)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue