Skip to content

Commit

Permalink
Allow to override the pull policy of the controller in 'kudo init' (#…
Browse files Browse the repository at this point in the history
…1507)

This makes it easier to deploy KUDO in test environments where a KUDO image is available in the cluster but not in any repository.

Signed-off-by: Jan Schlicht <jan@d2iq.com>

Co-authored-by: Andreas Neumann <aneumann@mesosphere.com>
  • Loading branch information
Jan Schlicht and ANeumann82 committed May 13, 2020
1 parent 89fe2dc commit 27aa546
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
6 changes: 4 additions & 2 deletions hack/run-e2e-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ docker build . \
-t "kudobuilder/controller:$VERSION"

# Generate the kudo.yaml that is used to install KUDO while running e2e-test
./bin/kubectl-kudo init --webhook InstanceValidation --unsafe-self-signed-webhook-ca --dry-run --output yaml --kudo-image kudobuilder/controller:$VERSION \
| sed -E -e '/imagePullPolicy/ s/Always/Never/' \
./bin/kubectl-kudo init --webhook InstanceValidation \
--unsafe-self-signed-webhook-ca --dry-run --output yaml \
--kudo-image kudobuilder/controller:$VERSION \
--kudo-image-pull-policy Never \
> test/manifests/kudo.yaml

sed "s/%version%/$VERSION/" kudo-e2e-test.yaml.tmpl > kudo-e2e-test.yaml
Expand Down
13 changes: 13 additions & 0 deletions pkg/kudoctl/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type initCmd struct {
out io.Writer
fs afero.Fs
image string
imagePullPolicy string
dryRun bool
output string
version string
Expand Down Expand Up @@ -102,6 +103,7 @@ func newInitCmd(fs afero.Fs, out io.Writer) *cobra.Command {
f := cmd.Flags()
f.BoolVarP(&i.clientOnly, "client-only", "c", false, "If set does not install KUDO on the server")
f.StringVarP(&i.image, "kudo-image", "i", "", "Override KUDO controller image and/or version")
f.StringVarP(&i.imagePullPolicy, "kudo-image-pull-policy", "", "", "Override KUDO controller image pull policy")
f.StringVarP(&i.version, "version", "", "", "Override KUDO controller version of the KUDO image")
f.StringVarP(&i.output, "output", "o", "", "Output format")
f.BoolVar(&i.dryRun, "dry-run", false, "Do not install local or remote")
Expand Down Expand Up @@ -148,6 +150,17 @@ func (initCmd *initCmd) run() error {
if initCmd.image != "" {
opts.Image = initCmd.image
}
if initCmd.imagePullPolicy != "" {
switch initCmd.imagePullPolicy {
case
"Always",
"Never",
"IfNotPresent":
opts.ImagePullPolicy = initCmd.imagePullPolicy
default:
return fmt.Errorf("Unknown image pull policy %s, must be one of 'Always', 'IfNotPresent' or 'Never'", initCmd.imagePullPolicy)
}
}

//TODO: implement output=yaml|json (define a type for output to constrain)
//define an Encoder to replace YAMLWriter
Expand Down
3 changes: 2 additions & 1 deletion pkg/kudoctl/kudoinit/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func generateDeployment(opts kudoinit.Options) *appsv1.StatefulSet {

secretDefaultMode := int32(420)
image := opts.Image
imagePullPolicy := v1.PullPolicy(opts.ImagePullPolicy)
s := &appsv1.StatefulSet{
TypeMeta: metav1.TypeMeta{
Kind: "StatefulSet",
Expand Down Expand Up @@ -127,7 +128,7 @@ func generateDeployment(opts kudoinit.Options) *appsv1.StatefulSet {
{Name: "ENABLE_WEBHOOKS", Value: strconv.FormatBool(opts.HasWebhooksEnabled())},
},
Image: image,
ImagePullPolicy: "Always",
ImagePullPolicy: imagePullPolicy,
Name: "manager",
Ports: []v1.ContainerPort{
// name matters for service
Expand Down
3 changes: 3 additions & 0 deletions pkg/kudoctl/kudoinit/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ type Options struct {
TerminationGracePeriodSeconds int64
// Image defines the image to be used
Image string
// ImagePullPolicy sets the pull policy of the image
ImagePullPolicy string
// List of enabled webhooks
Webhooks []string
// Using self-signed webhook CA bundle
Expand All @@ -40,6 +42,7 @@ func NewOptions(v string, ns string, sa string, webhooks []string, selfSignedWeb
Namespace: ns,
TerminationGracePeriodSeconds: defaultGracePeriod,
Image: fmt.Sprintf("kudobuilder/controller:v%v", v),
ImagePullPolicy: "Always",
Webhooks: webhooks,
ServiceAccount: sa,
SelfSignedWebhookCA: selfSignedWebhookCA,
Expand Down

0 comments on commit 27aa546

Please sign in to comment.