-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
configure ImagePullPolicy via operator CR
Allow administrator to set desired ImagePullPolicy through NetworkAddonsConfig CR. Until now, it was possible only using operator's environment variables.
- Loading branch information
Showing
10 changed files
with
79 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -5,3 +5,4 @@ metadata: | |
spec: | ||
multus: {} | ||
linuxBridge: {} | ||
imagePullPolicy: Always |
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,54 @@ | ||
package network | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
v1 "k8s.io/api/core/v1" | ||
|
||
opv1alpha1 "github.com/kubevirt/cluster-network-addons-operator/pkg/apis/networkaddonsoperator/v1alpha1" | ||
) | ||
|
||
const defaultImagePullPolicy = string(v1.PullIfNotPresent) | ||
|
||
func validateImagePullPolicy(conf *opv1alpha1.NetworkAddonsConfigSpec) []error { | ||
if conf.ImagePullPolicy == "" { | ||
return []error{} | ||
} | ||
|
||
if valid := verifyPullPolicyType(conf.ImagePullPolicy); !valid { | ||
return []error{errors.Errorf("requested imagePullPolicy '%s' is not valid", conf.ImagePullPolicy)} | ||
} | ||
|
||
return []error{} | ||
} | ||
|
||
func fillDefaultsImagePullPolicy(conf, previous *opv1alpha1.NetworkAddonsConfigSpec) { | ||
if conf.ImagePullPolicy == "" { | ||
if previous != nil && previous.ImagePullPolicy != "" { | ||
conf.ImagePullPolicy = previous.ImagePullPolicy | ||
} else { | ||
conf.ImagePullPolicy = defaultImagePullPolicy | ||
} | ||
} | ||
} | ||
|
||
func changeSafeImagePullPolicy(prev, next *opv1alpha1.NetworkAddonsConfigSpec) []error { | ||
if prev.ImagePullPolicy != "" && prev.ImagePullPolicy != next.ImagePullPolicy { | ||
return []error{errors.Errorf("cannot modify ImagePullPolicy configuration once components were deployed")} | ||
} | ||
return nil | ||
} | ||
|
||
// Verify if the value is a valid PullPolicy | ||
func verifyPullPolicyType(policy string) bool { | ||
imagePullPolicy := v1.PullPolicy(policy) | ||
switch imagePullPolicy { | ||
case v1.PullAlways: | ||
return true | ||
case v1.PullNever: | ||
return true | ||
case v1.PullIfNotPresent: | ||
return true | ||
default: | ||
return false | ||
} | ||
} |
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