Skip to content

Commit

Permalink
up: add pull policy to context and pass it properly to cluster add
Browse files Browse the repository at this point in the history
  • Loading branch information
mfojtik authored and deads2k committed May 9, 2018
1 parent 948705f commit 9941843
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 17 deletions.
2 changes: 1 addition & 1 deletion install/openshift-web-console-operator/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: template.openshift.io/v1
kind: Template
parameters:
- name: IMAGE
value: openshift/origin-control-plane:latest
value: openshift/origin-hypershift:latest
- name: OPENSHIFT_PULL_POLICY
value: Always
- name: NAMESPACE
Expand Down
2 changes: 1 addition & 1 deletion pkg/oc/bootstrap/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions pkg/oc/bootstrap/clusteradd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func NewCmdAdd(name, fullName string, out, errout io.Writer) *cobra.Command {
if err := config.Check(); err != nil {
return err
}
if err := config.Run(); err != nil {
if err := config.Run(c); err != nil {
return err
}

Expand All @@ -110,10 +110,13 @@ func NewCmdAdd(name, fullName string, out, errout io.Writer) *cobra.Command {
}

// Start runs the start tasks ensuring that they are executed in sequence
func (c *ClusterAddConfig) Run() error {
func (c *ClusterAddConfig) Run(cmd *cobra.Command) error {
defaultPullPolicy := "Always"
if len(c.ImageTag) > 0 {
defaultPullPolicy = "IfNotPresent"
}
componentsToInstall := []componentinstall.Component{}
installContext, err := componentinstall.NewComponentInstallContext(c.cliImage(), c.imageFormat(), c.BaseDir,
c.ServerLogLevel)
installContext, err := componentinstall.NewComponentInstallContext(c.cliImage(), c.imageFormat(), defaultPullPolicy, c.BaseDir, c.ServerLogLevel)
if err != nil {
return err
}
Expand Down
18 changes: 17 additions & 1 deletion pkg/oc/bootstrap/clusteradd/componentinstall/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,29 @@ import (
const adminKubeConfigFileName = "admin.kubeconfig"

type Context interface {
// ClusterAdminClientConfig is the cluster admin client configuration components can use to make their client.
ClusterAdminClientConfig() *restclient.Config

// BaseDir is the base directory that component should use to store files/logs/etc.
BaseDir() string
ClientImage() string
// ImageFormat provides information about the image pull spec format. This is handy when trying to use different registries or image names.
ImageFormat() string

// ComponentLogLevel provides information about verbosity the component should log the messages.
ComponentLogLevel() int

// ImagePullPolicy provides information about what pull policy for images should be used. This is usually based on the presence of the `--tag`
// flag which in that case the pull policy will be IfNotExists instead of Always. That allows local development without pulling the images.
ImagePullPolicy() string
}

type installContext struct {
restConfig *restclient.Config
clientImage string
imageFormat string
baseDir string
pullPolicy string
logLevel int
}

Expand Down Expand Up @@ -52,7 +63,11 @@ func (c *installContext) ClientImage() string {
return c.clientImage
}

func NewComponentInstallContext(clientImageName, imageFormat, baseDir string, logLevel int) (Context, error) {
func (c *installContext) ImagePullPolicy() string {
return c.pullPolicy
}

func NewComponentInstallContext(clientImageName, imageFormat, pullPolicy, baseDir string, logLevel int) (Context, error) {
clusterAdminConfigBytes, err := ioutil.ReadFile(path.Join(baseDir, kubeapiserver.KubeAPIServerDirName, adminKubeConfigFileName))
if err != nil {
return nil, err
Expand All @@ -67,5 +82,6 @@ func NewComponentInstallContext(clientImageName, imageFormat, baseDir string, lo
baseDir: baseDir,
logLevel: logLevel,
imageFormat: imageFormat,
pullPolicy: pullPolicy,
}, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ func (c *WebConsoleOperatorComponentOptions) Install(dockerClient dockerhelper.I
imageTemplate.Latest = false

params := map[string]string{
"IMAGE": c.InstallContext.ClientImage(),
"LOGLEVEL": fmt.Sprintf("%d", c.InstallContext.ComponentLogLevel()),
"COMPONENT_IMAGE": imageTemplate.ExpandOrDie("web-console"),
"COMPONENT_LOGLEVEL": fmt.Sprintf("%d", c.InstallContext.ComponentLogLevel()),
"NAMESPACE": namespace,
"IMAGE": imageTemplate.ExpandOrDie("hypershift"),
"LOGLEVEL": fmt.Sprintf("%d", c.InstallContext.ComponentLogLevel()),
"COMPONENT_IMAGE": imageTemplate.ExpandOrDie("web-console"),
"COMPONENT_LOGLEVEL": fmt.Sprintf("%d", c.InstallContext.ComponentLogLevel()),
"NAMESPACE": namespace,
"OPENSHIFT_PULL_POLICY": c.InstallContext.ImagePullPolicy(),
}
glog.V(2).Infof("instantiating template service broker template with parameters %v", params)

glog.V(2).Infof("instantiating webconsole-operator template with parameters %v", params)

component := componentinstall.Template{
Name: "openshift-web-console-operator",
Expand All @@ -55,7 +57,7 @@ func (c *WebConsoleOperatorComponentOptions) Install(dockerClient dockerhelper.I

// wait until the webconsole to an available endpoint
WaitCondition: func() (bool, error) {
glog.V(2).Infof("polling for webconsole endpoint availability")
glog.V(2).Infof("polling for web-console availability ...")
deployment, err := kubeAdminClient.AppsV1().Deployments("openshift-web-console").Get("webconsole", metav1.GetOptions{})
if apierrors.IsNotFound(err) {
return false, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/oc/bootstrap/docker/run_self_hosted.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func (c *ClusterUpConfig) StartSelfHosted(out io.Writer) error {
return err
}

installContext, err := componentinstall.NewComponentInstallContext(c.openshiftImage(), c.imageFormat(), c.BaseDir, c.ServerLogLevel)
installContext, err := componentinstall.NewComponentInstallContext(c.cliImage(), c.imageFormat(), c.defaultPullPolicy, c.BaseDir, c.ServerLogLevel)
if err != nil {
return err
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/oc/bootstrap/docker/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,10 @@ func (c *ClusterUpConfig) Complete(cmd *cobra.Command) error {
// Set the ImagePullPolicy field in static pods and components based in whether users specified
// the --tag flag or not.
c.defaultPullPolicy = "Always"
if cmd.Flag("image").Changed || cmd.Flag("tag").Changed {
if len(c.ImageTag) > 0 {
c.defaultPullPolicy = "IfNotPresent"
}
glog.V(5).Infof("Using %q as default image pull policy", c.defaultPullPolicy)

// Get the default client config for login
var err error
Expand Down Expand Up @@ -500,6 +501,9 @@ func (c *ClusterUpConfig) Start(out io.Writer) error {
if len(c.ComponentsToEnable) > 0 {
args := append([]string{}, "--image="+c.ImageTemplate.Format)
args = append(args, "--base-dir="+c.BaseDir)
if len(c.ImageTag) > 0 {
args = append(args, "--tag="+c.ImageTag)
}
args = append(args, c.ComponentsToEnable...)

if err := c.ClusterAdd.ParseFlags(args); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion test/extended/testdata/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9941843

Please sign in to comment.