Skip to content

Commit

Permalink
Set imagePullPolicy always for devel version (#666)
Browse files Browse the repository at this point in the history
When referencing a 'devel' version on install, the existing cluster
could have downloaded previous versions of the images, if we don't specify
imagePullPolicy as always the images could be old, leading to testing
issues.

This way we act very close to the best practices defined in [1]

Fixes-Issue: submariner-io/submariner#781

[1] https://kubernetes.io/docs/concepts/configuration/overview/#container-images

Signed-off-by: Miguel Angel Ajo <[email protected]>
  • Loading branch information
mangelajo authored Sep 1, 2020
1 parent b6c8a4f commit a1aa7b6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
operatorclient "github.com/openshift/cluster-dns-operator/pkg/operator/client"
submarinerv1alpha1 "github.com/submariner-io/submariner-operator/pkg/apis/submariner/v1alpha1"
"github.com/submariner-io/submariner-operator/pkg/controller/helpers"
"github.com/submariner-io/submariner-operator/pkg/images"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -202,7 +204,7 @@ func newLighthouseAgent(cr *submarinerv1alpha1.ServiceDiscovery) *appsv1.Deploym
{
Name: "submariner-lighthouse-agent",
Image: getImagePath(cr, serviceDiscoveryImage),
ImagePullPolicy: "IfNotPresent",
ImagePullPolicy: images.GetPullPolicy(cr.Spec.Version),
Env: []corev1.EnvVar{
{Name: "SUBMARINER_NAMESPACE", Value: cr.Spec.Namespace},
{Name: "SUBMARINER_CLUSTERID", Value: cr.Spec.ClusterID},
Expand Down Expand Up @@ -290,7 +292,7 @@ func newLigthhouseCoreDNSDeployment(cr *submarinerv1alpha1.ServiceDiscovery) *ap
{
Name: lighthouseCoreDNSName,
Image: getImagePath(cr, lighthouseCoreDNSImage),
ImagePullPolicy: "IfNotPresent",
ImagePullPolicy: images.GetPullPolicy(cr.Spec.Version),
Args: []string{
"-conf",
"/etc/coredns/Corefile",
Expand Down
8 changes: 5 additions & 3 deletions pkg/controller/submariner/submariner_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ func newEnginePodTemplate(cr *submopv1a1.Submariner) corev1.PodTemplateSpec {
{
Name: "submariner",
Image: getImagePath(cr, engineImage),
ImagePullPolicy: images.GetPullPolicy(cr.Spec.Version),
Command: []string{"submariner.sh"},
SecurityContext: &security_context_all_caps_privileged,
VolumeMounts: []corev1.VolumeMount{
Expand Down Expand Up @@ -497,8 +498,9 @@ func newRouteAgentDaemonSet(cr *submopv1a1.Submariner) *appsv1.DaemonSet {
TerminationGracePeriodSeconds: &terminationGracePeriodSeconds,
Containers: []corev1.Container{
{
Name: "submariner-routeagent",
Image: getImagePath(cr, routeAgentImage),
Name: "submariner-routeagent",
Image: getImagePath(cr, routeAgentImage),
ImagePullPolicy: images.GetPullPolicy(cr.Spec.Version),
// FIXME: Should be entrypoint script, find/use correct file for routeagent
Command: []string{"submariner-route-agent.sh"},
SecurityContext: &security_context_all_cap_allow_escal,
Expand Down Expand Up @@ -570,7 +572,7 @@ func newGlobalnetDaemonSet(cr *submopv1a1.Submariner) *appsv1.DaemonSet {
{
Name: "submariner-globalnet",
Image: getImagePath(cr, globalnetImage),
ImagePullPolicy: "IfNotPresent",
ImagePullPolicy: images.GetPullPolicy(cr.Spec.Version),
SecurityContext: &security_context_all_cap_allow_escal,
VolumeMounts: []corev1.VolumeMount{
{Name: "host-slash", MountPath: "/host", ReadOnly: true},
Expand Down
10 changes: 10 additions & 0 deletions pkg/images/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"strings"

v1 "k8s.io/api/core/v1"

"github.com/submariner-io/submariner-operator/pkg/subctl/operator/submarinerop/deployment"
)

Expand All @@ -23,6 +25,14 @@ func GetImagePath(repo, version, component string) string {
return path
}

func GetPullPolicy(version string) v1.PullPolicy {
if version == "devel" {
return v1.PullAlways
} else {
return v1.PullIfNotPresent
}
}

func ParseOperatorImage(operatorImage string) (string, string) {
i := strings.LastIndex(operatorImage, ":")
var repository string
Expand Down

0 comments on commit a1aa7b6

Please sign in to comment.