Skip to content

Commit 294f07f

Browse files
Merge pull request #16631 from mjudeikis/oc-cluster-up-pv-number
Automatic merge from submit-queue (batch tested with PRs 17289, 16631). clusterup add .skip_pv marker Added .skip_pv marker for oc cluster up command. When the marker is detected in the PV folder - no PV's will be created leaving this configuration for the user. as per https://trello.com/c/HbpYqEkm/1250-1-cluster-up-option-to-set-number-of-pvs-to-create-clusterup added pv count. @csrwng @jim-minter
2 parents dd0b83d + 7f448c0 commit 294f07f

File tree

3 files changed

+35
-11
lines changed

3 files changed

+35
-11
lines changed

pkg/oc/bootstrap/docker/openshift/pvsetup.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package openshift
33
import (
44
"bytes"
55
"fmt"
6+
"os"
67

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

1920
const (
20-
pvCount = 100
21-
pvSetupJobName = "persistent-volume-setup"
22-
pvInstallerSA = "pvinstaller"
23-
pvSetupNamespace = "default"
21+
pvCount = 100
22+
pvSetupJobName = "persistent-volume-setup"
23+
pvInstallerSA = "pvinstaller"
24+
pvSetupNamespace = "default"
25+
pvIgnoreMarkerFile = ".skip_pv"
2426
)
2527

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

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

99-
setupJob := persistentStorageSetupJob(pvSetupJobName, dir, h.image)
100-
if _, err = kclient.Batch().Jobs(pvSetupNamespace).Create(setupJob); err != nil {
101-
return errors.NewError("cannot create job to setup persistent volumes (%s/%s)", pvSetupNamespace, pvSetupJobName).WithCause(err).WithDetails(h.OriginLog())
102+
// check if we need to create pv's
103+
_, err = os.Stat(fmt.Sprintf("%s/%s", HostPersistentVolumesDir, pvIgnoreMarkerFile))
104+
if !os.IsNotExist(err) {
105+
fmt.Printf("Skip persistent volume creation \n")
106+
} else {
107+
setupJob := persistentStorageSetupJob(pvSetupJobName, dir, h.image, pvCount)
108+
if _, err = kclient.Batch().Jobs(pvSetupNamespace).Create(setupJob); err != nil {
109+
return errors.NewError("cannot create job to setup persistent volumes (%s/%s)", pvSetupNamespace, pvSetupJobName).WithCause(err).WithDetails(h.OriginLog())
110+
}
102111
}
103-
104112
return nil
105113
}
106114

@@ -138,7 +146,7 @@ func (h *Helper) ensurePVInstallerSA(authorizationClient authorizationtypedclien
138146
return nil
139147
}
140148

141-
func persistentStorageSetupJob(name, dir, image string) *kbatch.Job {
149+
func persistentStorageSetupJob(name, dir, image string, pvCount int) *kbatch.Job {
142150
// Job volume
143151
volume := kapi.Volume{}
144152
volume.Name = "pvdir"

pkg/oc/bootstrap/docker/up.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ type CommonStartConfig struct {
222222
HTTPSProxy string
223223
NoProxy []string
224224
CACert string
225+
PVCount int
225226

226227
dockerClient dockerhelper.Interface
227228
dockerHelper *dockerhelper.Helper
@@ -910,7 +911,7 @@ func (c *ClientStartConfig) StartOpenShift(out io.Writer) error {
910911
return err
911912
}
912913

913-
err = c.OpenShiftHelper().SetupPersistentStorage(authorizationClient.Authorization(), kClient, securityClient, c.HostPersistentVolumesDir)
914+
err = c.OpenShiftHelper().SetupPersistentStorage(authorizationClient.Authorization(), kClient, securityClient, c.HostPersistentVolumesDir, c.HostPersistentVolumesDir)
914915
if err != nil {
915916
return err
916917
}

test/extended/clusterup.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ function os::test::extended::clusterup::verify_persistent_volumes () {
5353
os::cmd::expect_success "oc login -u developer"
5454
}
5555

56+
function os::test::extended::clusterup::skip_persistent_volumes () {
57+
mkdir -p /tmp/pv
58+
touch /tmp/pv/.skip_pv
59+
os::cmd::expect_success_and_text "oc cluster up --host-pv-dir=/tmp/pv/" "Skip persistent volume creation"
60+
os::cmd::expect_success "oc login -u system:admin"
61+
os::cmd::expect_success_and_text "oc get pv | wc -l" "0"
62+
}
63+
5664
function os::test::extended::clusterup::verify_metrics () {
5765
os::cmd::expect_success "oc login -u system:admin"
5866
os::cmd::expect_success_and_text "oc get pods -n openshift-infra" "metrics-deployer"
@@ -269,6 +277,12 @@ function os::test::extended::clusterup::portinuse_cleanup () {
269277
}
270278

271279

280+
# Verifies that clusterup handle different scenarios with persistent volumes setup
281+
function os::test::extended::clusterup::persistentvolumes () {
282+
os::test::extended::clusterup::skip_persistent_volumes
283+
rm -rf /tmp/pv
284+
}
285+
272286
readonly default_tests=(
273287
"service_catalog"
274288
"noargs"
@@ -277,6 +291,7 @@ readonly default_tests=(
277291
"numerichostname"
278292
"portinuse"
279293
"svcaccess"
294+
"persistentvolumes"
280295

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

0 commit comments

Comments
 (0)