@@ -18,13 +18,14 @@ package main
18
18
19
19
import (
20
20
"context"
21
+ "errors"
21
22
"fmt"
22
23
23
24
"github.com/spf13/cobra"
24
25
"github.com/spf13/viper"
25
26
"k8s.io/klog"
26
27
27
- "k8s.io/apimachinery/pkg/api/errors"
28
+ k8serrors "k8s.io/apimachinery/pkg/api/errors"
28
29
29
30
"github.com/minio/direct-csi/pkg/utils"
30
31
"github.com/minio/direct-csi/pkg/utils/installer"
49
50
loopBackOnly = false
50
51
nodeSelectorValues = []string {}
51
52
tolerationValues = []string {}
53
+ seccompProfile = ""
54
+ apparmorProfile = ""
52
55
)
53
56
54
57
func init () {
@@ -61,6 +64,8 @@ func init() {
61
64
installCmd .PersistentFlags ().MarkDeprecated ("crd" , "Will be removed in version 1.5 or greater" )
62
65
installCmd .PersistentFlags ().StringSliceVarP (& nodeSelectorValues , "node-selector" , "n" , nodeSelectorValues , "node selector parameters" )
63
66
installCmd .PersistentFlags ().StringSliceVarP (& tolerationValues , "tolerations" , "t" , tolerationValues , "tolerations parameters" )
67
+ installCmd .PersistentFlags ().StringVarP (& seccompProfile , "seccomp-profile" , "" , seccompProfile , "set Seccomp profile" )
68
+ installCmd .PersistentFlags ().StringVarP (& apparmorProfile , "apparmor-profile" , "" , apparmorProfile , "set Apparmor profile" )
64
69
65
70
installCmd .PersistentFlags ().BoolVarP (& loopBackOnly , "loopback-only" , "" , loopBackOnly , "Uses 4 free loopback devices per node and treat them as DirectCSIDrive resources. This is recommended only for testing/development purposes" )
66
71
installCmd .PersistentFlags ().MarkHidden ("loopback-only" )
@@ -90,16 +95,27 @@ func install(ctx context.Context, args []string) error {
90
95
utils .Init ()
91
96
92
97
if err := installer .CreateNamespace (ctx , identity , dryRun ); err != nil {
93
- if ! errors .IsAlreadyExists (err ) {
98
+ if ! k8serrors .IsAlreadyExists (err ) {
94
99
return err
95
100
}
96
101
}
97
102
if ! dryRun {
98
103
klog .Infof ("'%s' namespace created" , utils .Bold (identity ))
99
104
}
100
105
106
+ if err := installer .CreatePodSecurityPolicy (ctx , identity , dryRun ); err != nil {
107
+ switch {
108
+ case errors .Is (err , installer .ErrKubeVersionNotSupported ):
109
+ klog .Infof ("pod security policy is not supported in your kubernetes" )
110
+ case ! k8serrors .IsAlreadyExists (err ):
111
+ return err
112
+ }
113
+ } else if ! dryRun {
114
+ klog .Infof ("'%s' pod security policy created" , utils .Bold (identity ))
115
+ }
116
+
101
117
if err := installer .CreateRBACRoles (ctx , identity , dryRun ); err != nil {
102
- if ! errors .IsAlreadyExists (err ) {
118
+ if ! k8serrors .IsAlreadyExists (err ) {
103
119
return err
104
120
}
105
121
}
@@ -116,14 +132,14 @@ func install(ctx context.Context, args []string) error {
116
132
117
133
crdInstall:
118
134
if err := registerCRDs (ctx , identity ); err != nil {
119
- if ! errors .IsAlreadyExists (err ) {
135
+ if ! k8serrors .IsAlreadyExists (err ) {
120
136
return err
121
137
}
122
138
// if it exists
123
139
if ! dryRun && overwriteCRD {
124
140
klog .V (4 ).Infof ("overwriting CRDs" )
125
141
if err := unregisterCRDs (ctx ); err != nil {
126
- if ! errors .IsNotFound (err ) {
142
+ if ! k8serrors .IsNotFound (err ) {
127
143
return err
128
144
}
129
145
}
@@ -136,7 +152,7 @@ crdInstall:
136
152
}
137
153
138
154
if err := installer .CreateCSIDriver (ctx , identity , dryRun ); err != nil {
139
- if ! errors .IsAlreadyExists (err ) {
155
+ if ! k8serrors .IsAlreadyExists (err ) {
140
156
return err
141
157
}
142
158
}
@@ -145,7 +161,7 @@ crdInstall:
145
161
}
146
162
147
163
if err := installer .CreateStorageClass (ctx , identity , dryRun ); err != nil {
148
- if ! errors .IsAlreadyExists (err ) {
164
+ if ! k8serrors .IsAlreadyExists (err ) {
149
165
return err
150
166
}
151
167
}
@@ -154,16 +170,16 @@ crdInstall:
154
170
}
155
171
156
172
if err := installer .CreateService (ctx , identity , dryRun ); err != nil {
157
- if ! errors .IsAlreadyExists (err ) {
173
+ if ! k8serrors .IsAlreadyExists (err ) {
158
174
return err
159
175
}
160
176
}
161
177
if ! dryRun {
162
178
klog .Infof ("'%s' service created" , utils .Bold (identity ))
163
179
}
164
180
165
- if err := installer .CreateDaemonSet (ctx , identity , image , dryRun , registry , org , loopBackOnly , nodeSelector , tolerations ); err != nil {
166
- if ! errors .IsAlreadyExists (err ) {
181
+ if err := installer .CreateDaemonSet (ctx , identity , image , dryRun , registry , org , loopBackOnly , nodeSelector , tolerations , seccompProfile , apparmorProfile ); err != nil {
182
+ if ! k8serrors .IsAlreadyExists (err ) {
167
183
return err
168
184
}
169
185
}
@@ -172,7 +188,7 @@ crdInstall:
172
188
}
173
189
174
190
if err := installer .CreateDeployment (ctx , identity , image , dryRun , registry , org ); err != nil {
175
- if ! errors .IsAlreadyExists (err ) {
191
+ if ! k8serrors .IsAlreadyExists (err ) {
176
192
return err
177
193
}
178
194
}
@@ -182,7 +198,7 @@ crdInstall:
182
198
183
199
if admissionControl {
184
200
if err := installer .RegisterDriveValidationRules (ctx , identity , dryRun ); err != nil {
185
- if ! errors .IsAlreadyExists (err ) {
201
+ if ! k8serrors .IsAlreadyExists (err ) {
186
202
return err
187
203
}
188
204
}
0 commit comments