Skip to content

Commit

Permalink
Merge pull request #127 from copejon/do-not-pull-image-always
Browse files Browse the repository at this point in the history
Change default pull policy to IfNotPresent to support offline demoing.
  • Loading branch information
jeffvance committed Apr 30, 2018
2 parents bf0e29b + 5dea552 commit 21ccaf3
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 13 deletions.
8 changes: 7 additions & 1 deletion cmd/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var (
configPath string
masterURL string
importerImage string
pullPolicy string
)

// The optional importer image is obtained here along with the supported flags.
Expand All @@ -30,11 +31,16 @@ func init() {
flag.StringVar(&configPath, "kubeconfig", os.Getenv("KUBECONFIG"), "(Optional) Overrides $KUBECONFIG")
flag.StringVar(&masterURL, "server", "", "(Optional) URL address of a remote api server. Do not set for local clusters.")
flag.Parse()

// env variables
importerImage = os.Getenv(IMPORTER_IMAGE)
if importerImage == "" {
importerImage = common.IMPORTER_DEFAULT_IMAGE
}
pullPolicy = common.IMPORTER_DEFAULT_PULL_POLICY
if pp := os.Getenv(common.IMPORTER_PULL_POLICY); len(pp) != 0 {
pullPolicy = pp
}
glog.Infof("init: complete: CDI controller will create the %q version of the importer\n", importerImage)
}

Expand All @@ -50,7 +56,7 @@ func main() {
informerFactory := informers.NewSharedInformerFactory(client, common.DEFAULT_RESYNC_PERIOD)
pvcInformer := informerFactory.Core().V1().PersistentVolumeClaims().Informer()

cdiController, err := controller.NewController(client, pvcInformer, importerImage)
cdiController, err := controller.NewController(client, pvcInformer, importerImage, pullPolicy)
if err != nil {
glog.Fatal("Error creating CDI controller: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion manifests/controller/cdi-controller-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ spec:
containers:
- name: cdi-controller
image: kubevirt/cdi-controller:0.4.0-alpha.0
imagePullPolicy: Always
imagePullPolicy: IfNotPresent
22 changes: 14 additions & 8 deletions pkg/common/common.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
package common

import "time"
import (
"time"

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

// Common types and constants used by the importer and controller.
// TODO: maybe the vm cloner can use these common values

const (
CDI_VERSION = "0.4.0-alpha.0"
CDI_VERSION = "0.4.0-alpha.0"

IMPORTER_DEFAULT_IMAGE = "docker.io/kubevirt/cdi-importer:" + CDI_VERSION
CDI_LABEL_KEY = "app"
CDI_LABEL_VALUE = "containerized-data-importer"
CDI_LABEL_SELECTOR = CDI_LABEL_KEY + "=" + CDI_LABEL_VALUE
CDI_LABEL_KEY = "app"
CDI_LABEL_VALUE = "containerized-data-importer"
CDI_LABEL_SELECTOR = CDI_LABEL_KEY + "=" + CDI_LABEL_VALUE

// host file constants:
IMPORTER_WRITE_DIR = "/data"
Expand All @@ -21,10 +25,12 @@ const (
IMPORTER_PODNAME = "importer"
IMPORTER_DATA_DIR = "/data"
IMPORTER_S3_HOST = "s3.amazonaws.com"
IMPORTER_DEFAULT_PULL_POLICY = string(v1.PullIfNotPresent)
// env var names
IMPORTER_ENDPOINT = "IMPORTER_ENDPOINT"
IMPORTER_ACCESS_KEY_ID = "IMPORTER_ACCESS_KEY_ID"
IMPORTER_SECRET_KEY = "IMPORTER_SECRET_KEY"
IMPORTER_PULL_POLICY = "IMPORTER_PULL_POLICY"
IMPORTER_ENDPOINT = "IMPORTER_ENDPOINT"
IMPORTER_ACCESS_KEY_ID = "IMPORTER_ACCESS_KEY_ID"
IMPORTER_SECRET_KEY = "IMPORTER_SECRET_KEY"
// key names expected in credential secret
KeyAccess = "accessKeyId"
KeySecret = "secretKey"
Expand Down
5 changes: 4 additions & 1 deletion pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,19 @@ type Controller struct {
queue workqueue.RateLimitingInterface
pvcInformer cache.SharedIndexInformer
importerImage string
pullPolicy string // Options: IfNotPresent, Always, or Never
}

func NewController(client kubernetes.Interface, pvcInformer cache.SharedIndexInformer, importerImage string) (*Controller, error) {
func NewController(client kubernetes.Interface, pvcInformer cache.SharedIndexInformer, importerImage string, pullPolicy string) (*Controller, error) {

queue := workqueue.NewRateLimitingQueue(workqueue.DefaultControllerRateLimiter())

c := &Controller{
clientset: client,
queue: queue,
pvcInformer: pvcInformer,
importerImage: importerImage,
pullPolicy: pullPolicy,
}

// Bind the Index/Informer to the queue only for new pvcs
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ var _ = Describe("Controller", func() {
queue := workqueue.NewRateLimitingQueue(workqueue.DefaultControllerRateLimiter())

var err error // declare err here to prevent shadowing `controller`, declared in the outer block
controller, err = NewController(fakeClient, pvcInformer, common.IMPORTER_DEFAULT_IMAGE)
controller, err = NewController(fakeClient, pvcInformer, common.IMPORTER_DEFAULT_IMAGE, common.IMPORTER_DEFAULT_PULL_POLICY)
Expect(err).NotTo(HaveOccurred(), fmt.Sprintf("setupInformer failed to create controller: %v", err))
if op == opAdd || op == opUpdate {
objSource.Add(pvc)
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func (c *Controller) makeImporterPodSpec(ep, secret string, pvc *v1.PersistentVo
{
Name: common.IMPORTER_PODNAME,
Image: c.importerImage,
ImagePullPolicy: v1.PullAlways,
ImagePullPolicy: v1.PullPolicy(c.pullPolicy),
VolumeMounts: []v1.VolumeMount{
{
Name: "data-path",
Expand Down

0 comments on commit 21ccaf3

Please sign in to comment.