Skip to content

Commit

Permalink
add skip_pv marker to skip PV creation
Browse files Browse the repository at this point in the history
  • Loading branch information
mjudeikis committed Nov 14, 2017
1 parent d9cb533 commit 7f448c0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
28 changes: 18 additions & 10 deletions pkg/oc/bootstrap/docker/openshift/pvsetup.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package openshift
import (
"bytes"
"fmt"
"os"

kerrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -17,10 +18,11 @@ import (
)

const (
pvCount = 100
pvSetupJobName = "persistent-volume-setup"
pvInstallerSA = "pvinstaller"
pvSetupNamespace = "default"
pvCount = 100
pvSetupJobName = "persistent-volume-setup"
pvInstallerSA = "pvinstaller"
pvSetupNamespace = "default"
pvIgnoreMarkerFile = ".skip_pv"
)

const createPVScript = `#/bin/bash
Expand Down Expand Up @@ -81,7 +83,8 @@ for i in $(seq -f "%%04g" 1 %[1]d); do
done
`

func (h *Helper) SetupPersistentStorage(authorizationClient authorizationtypedclient.ClusterRoleBindingsGetter, kclient kclientset.Interface, securityClient securityclient.Interface, dir string) error {
// SetupPersistentStorage sets up persistent storage
func (h *Helper) SetupPersistentStorage(authorizationClient authorizationtypedclient.ClusterRoleBindingsGetter, kclient kclientset.Interface, securityClient securityclient.Interface, dir, HostPersistentVolumesDir string) error {
err := h.ensurePVInstallerSA(authorizationClient, kclient, securityClient)
if err != nil {
return err
Expand All @@ -96,11 +99,16 @@ func (h *Helper) SetupPersistentStorage(authorizationClient authorizationtypedcl
return errors.NewError("error retrieving job to setup persistent volumes (%s/%s)", pvSetupNamespace, pvSetupJobName).WithCause(err).WithDetails(h.OriginLog())
}

setupJob := persistentStorageSetupJob(pvSetupJobName, dir, h.image)
if _, err = kclient.Batch().Jobs(pvSetupNamespace).Create(setupJob); err != nil {
return errors.NewError("cannot create job to setup persistent volumes (%s/%s)", pvSetupNamespace, pvSetupJobName).WithCause(err).WithDetails(h.OriginLog())
// check if we need to create pv's
_, err = os.Stat(fmt.Sprintf("%s/%s", HostPersistentVolumesDir, pvIgnoreMarkerFile))
if !os.IsNotExist(err) {
fmt.Printf("Skip persistent volume creation \n")
} else {
setupJob := persistentStorageSetupJob(pvSetupJobName, dir, h.image, pvCount)
if _, err = kclient.Batch().Jobs(pvSetupNamespace).Create(setupJob); err != nil {
return errors.NewError("cannot create job to setup persistent volumes (%s/%s)", pvSetupNamespace, pvSetupJobName).WithCause(err).WithDetails(h.OriginLog())
}
}

return nil
}

Expand Down Expand Up @@ -138,7 +146,7 @@ func (h *Helper) ensurePVInstallerSA(authorizationClient authorizationtypedclien
return nil
}

func persistentStorageSetupJob(name, dir, image string) *kbatch.Job {
func persistentStorageSetupJob(name, dir, image string, pvCount int) *kbatch.Job {
// Job volume
volume := kapi.Volume{}
volume.Name = "pvdir"
Expand Down
3 changes: 2 additions & 1 deletion pkg/oc/bootstrap/docker/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ type CommonStartConfig struct {
HTTPSProxy string
NoProxy []string
CACert string
PVCount int

dockerClient dockerhelper.Interface
dockerHelper *dockerhelper.Helper
Expand Down Expand Up @@ -910,7 +911,7 @@ func (c *ClientStartConfig) StartOpenShift(out io.Writer) error {
return err
}

err = c.OpenShiftHelper().SetupPersistentStorage(authorizationClient.Authorization(), kClient, securityClient, c.HostPersistentVolumesDir)
err = c.OpenShiftHelper().SetupPersistentStorage(authorizationClient.Authorization(), kClient, securityClient, c.HostPersistentVolumesDir, c.HostPersistentVolumesDir)
if err != nil {
return err
}
Expand Down
15 changes: 15 additions & 0 deletions test/extended/clusterup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ function os::test::extended::clusterup::verify_persistent_volumes () {
os::cmd::expect_success "oc login -u developer"
}

function os::test::extended::clusterup::skip_persistent_volumes () {
mkdir -p /tmp/pv
touch /tmp/pv/.skip_pv
os::cmd::expect_success_and_text "oc cluster up --host-pv-dir=/tmp/pv/" "Skip persistent volume creation"
os::cmd::expect_success "oc login -u system:admin"
os::cmd::expect_success_and_text "oc get pv | wc -l" "0"
}

function os::test::extended::clusterup::verify_metrics () {
os::cmd::expect_success "oc login -u system:admin"
os::cmd::expect_success_and_text "oc get pods -n openshift-infra" "metrics-deployer"
Expand Down Expand Up @@ -269,6 +277,12 @@ function os::test::extended::clusterup::portinuse_cleanup () {
}


# Verifies that clusterup handle different scenarios with persistent volumes setup
function os::test::extended::clusterup::persistentvolumes () {
os::test::extended::clusterup::skip_persistent_volumes
rm -rf /tmp/pv
}

readonly default_tests=(
"service_catalog"
"noargs"
Expand All @@ -277,6 +291,7 @@ readonly default_tests=(
"numerichostname"
"portinuse"
"svcaccess"
"persistentvolumes"

# enable once https://github.com/openshift/origin/issues/16995 is fixed
# "default"
Expand Down

0 comments on commit 7f448c0

Please sign in to comment.