@@ -3,6 +3,7 @@ package openshift
3
3
import (
4
4
"bytes"
5
5
"fmt"
6
+ "os"
6
7
7
8
kerrors "k8s.io/apimachinery/pkg/api/errors"
8
9
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -17,10 +18,11 @@ import (
17
18
)
18
19
19
20
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"
24
26
)
25
27
26
28
const createPVScript = `#/bin/bash
@@ -81,7 +83,8 @@ for i in $(seq -f "%%04g" 1 %[1]d); do
81
83
done
82
84
`
83
85
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 {
85
88
err := h .ensurePVInstallerSA (authorizationClient , kclient , securityClient )
86
89
if err != nil {
87
90
return err
@@ -96,11 +99,16 @@ func (h *Helper) SetupPersistentStorage(authorizationClient authorizationtypedcl
96
99
return errors .NewError ("error retrieving job to setup persistent volumes (%s/%s)" , pvSetupNamespace , pvSetupJobName ).WithCause (err ).WithDetails (h .OriginLog ())
97
100
}
98
101
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
+ }
102
111
}
103
-
104
112
return nil
105
113
}
106
114
@@ -138,7 +146,7 @@ func (h *Helper) ensurePVInstallerSA(authorizationClient authorizationtypedclien
138
146
return nil
139
147
}
140
148
141
- func persistentStorageSetupJob (name , dir , image string ) * kbatch.Job {
149
+ func persistentStorageSetupJob (name , dir , image string , pvCount int ) * kbatch.Job {
142
150
// Job volume
143
151
volume := kapi.Volume {}
144
152
volume .Name = "pvdir"
0 commit comments