forked from apache/incubator-kie-kogito-serverless-operator
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…pache#362) * Fix apache#359 - Change pullpolicy conditionally based on image tag Signed-off-by: Ricardo Zanini <[email protected]> * Fix leftovers on rebase Signed-off-by: Ricardo Zanini <[email protected]> --------- Signed-off-by: Ricardo Zanini <[email protected]>
- Loading branch information
1 parent
7bbcc0e
commit 65f1c35
Showing
5 changed files
with
93 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright 2024 Apache Software Foundation (ASF) | ||
// | ||
// 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 kubernetes | ||
|
||
import ( | ||
"strings" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
// GetImagePullPolicy gets the default corev1.PullPolicy depending on the image tag specified. | ||
// It follows the conventions of docker client and OpenShift. If no tag specified, it assumes latest. | ||
// Returns PullAlways if latest tag, empty otherwise to let the cluster figure it out. | ||
func GetImagePullPolicy(imageTag string) corev1.PullPolicy { | ||
if len(imageTag) == 0 { | ||
return "" | ||
} | ||
idx := strings.LastIndex(imageTag, ":") | ||
if idx < 0 { | ||
return corev1.PullAlways | ||
} | ||
tag := imageTag[idx+1:] | ||
if tag == "latest" { | ||
return corev1.PullAlways | ||
} | ||
return "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright 2024 Apache Software Foundation (ASF) | ||
// | ||
// 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 kubernetes | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
v1 "k8s.io/api/core/v1" | ||
) | ||
|
||
func TestGetImagePullPolicy(t *testing.T) { | ||
type args struct { | ||
imageTag string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want v1.PullPolicy | ||
}{ | ||
{"Short name with latest", args{"ubi9-micro:latest"}, v1.PullAlways}, | ||
{"Long name with latest", args{"gcr.io/knative-releases/knative.dev/eventing/cmd/event_display:latest"}, v1.PullAlways}, | ||
{"No tag specified", args{"ubi9-micro"}, v1.PullAlways}, | ||
{"Short name with tag", args{"ubi9-micro:9.3.1-2"}, ""}, | ||
{"Long name with tag", args{"gcr.io/knative-releases/knative.dev/eventing/cmd/event_display:1.2"}, ""}, | ||
{"Empty tag", args{""}, ""}, | ||
{"Messy tag", args{":"}, ""}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
assert.Equalf(t, tt.want, GetImagePullPolicy(tt.args.imageTag), "GetImagePullPolicy(%v)", tt.args.imageTag) | ||
}) | ||
} | ||
} |