-
Notifications
You must be signed in to change notification settings - Fork 97
/
KubernetesDeployerProperties.java
executable file
·2522 lines (1966 loc) · 58.7 KB
/
KubernetesDeployerProperties.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright 2015-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.deployer.spi.kubernetes;
import java.util.ArrayList;
import java.util.List;
import io.fabric8.kubernetes.api.model.NodeAffinity;
import io.fabric8.kubernetes.api.model.PodAffinity;
import io.fabric8.kubernetes.api.model.PodAntiAffinity;
import io.fabric8.kubernetes.api.model.Volume;
import io.fabric8.kubernetes.api.model.VolumeMount;
import io.fabric8.kubernetes.client.Config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.cloud.deployer.spi.app.AppAdmin;
/**
* @author Florian Rosenberg
* @author Thomas Risberg
* @author Donovan Muller
* @author Ilayaperumal Gopinathan
* @author Leonardo Diniz
* @author Chris Schaefer
* @author David Turanski
* @author Enrique Medina Montenegro
* @author Chris Bono
* @author Corneil du Plessis
*/
@ConfigurationProperties(prefix = KubernetesDeployerProperties.KUBERNETES_DEPLOYER_PROPERTIES_PREFIX)
public class KubernetesDeployerProperties {
static final String KUBERNETES_DEPLOYER_PROPERTIES_PREFIX = "spring.cloud.deployer.kubernetes";
/**
* Constants for app deployment properties that don't have a deployer level default
* property.
*/
static final String KUBERNETES_DEPLOYMENT_NODE_SELECTOR = "spring.cloud.deployer.kubernetes.deployment.nodeSelector";
/**
* The maximum concurrent tasks allowed for this platform instance.
*/
private int maximumConcurrentTasks = 20;
/**
* The number of seconds to wait before terminating the container.
*/
private Long terminiationGracePeriodSeconds;
@NestedConfigurationProperty
private Config fabric8 = Config.autoConfigure(null);
public Config getFabric8() {
return this.fabric8;
}
public void setFabric8(Config fabric8) {
this.fabric8 = fabric8;
}
/**
* Encapsulates resources for Kubernetes Container resource limits
*/
public static class LimitsResources {
/**
* Container resource cpu limit.
*/
private String cpu;
/**
* Container resource memory limit.
*/
private String memory;
/**
* Container GPU vendor name for limit
*/
private String gpuVendor;
/**
* Container GPU count for limit.
*/
private String gpuCount;
public LimitsResources() {
}
/**
* 'All' args constructor
*
* @param cpu Container resource cpu limit
* @param memory Container resource memory limit
* @deprecated This method should no longer be used to set all fields at construct time.
* <p>
* Use the default constructor and set() methods instead.
*/
@Deprecated
public LimitsResources(String cpu, String memory) {
this.cpu = cpu;
this.memory = memory;
}
public String getCpu() {
return cpu;
}
public void setCpu(String cpu) {
this.cpu = cpu;
}
public String getMemory() {
return memory;
}
public void setMemory(String memory) {
this.memory = memory;
}
public String getGpuVendor() {
return gpuVendor;
}
public void setGpuVendor(String gpuVendor) {
this.gpuVendor = gpuVendor;
}
public String getGpuCount() {
return gpuCount;
}
public void setGpuCount(String gpuCount) {
this.gpuCount = gpuCount;
}
}
/**
* Encapsulates resources for Kubernetes Container resource requests
*/
public static class RequestsResources {
/**
* Container request limit.
*/
private String cpu;
/**
* Container memory limit.
*/
private String memory;
public RequestsResources() {
}
public RequestsResources(String cpu, String memory) {
this.cpu = cpu;
this.memory = memory;
}
public String getCpu() {
return cpu;
}
public void setCpu(String cpu) {
this.cpu = cpu;
}
public String getMemory() {
return memory;
}
public void setMemory(String memory) {
this.memory = memory;
}
}
public static class StatefulSet {
private VolumeClaimTemplate volumeClaimTemplate = new VolumeClaimTemplate();
public VolumeClaimTemplate getVolumeClaimTemplate() {
return volumeClaimTemplate;
}
public void setVolumeClaimTemplate(VolumeClaimTemplate volumeClaimTemplate) {
this.volumeClaimTemplate = volumeClaimTemplate;
}
public static class VolumeClaimTemplate {
/**
* VolumeClaimTemplate name
*/
private String name;
/**
* VolumeClaimTemplate storage.
*/
private String storage = "10m";
/**
* VolumeClaimTemplate storage class name.
*/
private String storageClassName;
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public String getStorage() {
return storage;
}
public void setStorage(String storage) {
this.storage = storage;
}
public String getStorageClassName() {
return storageClassName;
}
public void setStorageClassName(String storageClassName) {
this.storageClassName = storageClassName;
}
}
}
public static class Toleration {
private String effect;
private String key;
private String operator;
private Long tolerationSeconds;
private String value;
public String getEffect() {
return effect;
}
public void setEffect(String effect) {
this.effect = effect;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getOperator() {
return operator;
}
public void setOperator(String operator) {
this.operator = operator;
}
public Long getTolerationSeconds() {
return tolerationSeconds;
}
public void setTolerationSeconds(Long tolerationSeconds) {
this.tolerationSeconds = tolerationSeconds;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
static class KeyRef {
private String envVarName;
private String dataKey;
public void setEnvVarName(String envVarName) {
this.envVarName = envVarName;
}
public String getEnvVarName() {
return envVarName;
}
public void setDataKey(String dataKey) {
this.dataKey = dataKey;
}
public String getDataKey() {
return dataKey;
}
}
public static class SecretKeyRef extends KeyRef {
private String secretName;
public void setSecretName(String secretName) {
this.secretName = secretName;
}
public String getSecretName() {
return secretName;
}
}
public static class ConfigMapKeyRef extends KeyRef {
private String configMapName;
public void setConfigMapName(String configMapName) {
this.configMapName = configMapName;
}
public String getConfigMapName() {
return configMapName;
}
}
public static class PodSecurityContext {
/**
* The numeric user ID to run pod container processes under
*/
private Long runAsUser;
/**
* The numeric group id to run the entrypoint of the container process
*/
private Long runAsGroup;
/**
* Indicates that the container must run as a non-root user
*/
private Boolean runAsNonRoot;
/**
* The numeric group ID for the volumes of the pod
*/
private Long fsGroup;
/**
* Defines behavior of changing ownership and permission of the volume before being
* exposed inside pod (only applies to volume types which support fsGroup based
* ownership and permissions) - possible values are "OnRootMismatch", "Always"
*/
private String fsGroupChangePolicy;
/**
* The numeric group IDs applied to the pod container processes, in addition to the container's primary group ID
*/
private Long[] supplementalGroups;
/**
* The seccomp options to use for the pod containers
*/
private SeccompProfile seccompProfile;
/**
* The SELinux context to be applied to the pod containers
*/
private SELinuxOptions seLinuxOptions;
/**
* List of namespaced sysctls used for the pod (not used when spec.os.name is windows).
*/
private List<SysctlInfo> sysctls;
/**
* The Windows specific settings applied to all containers.
*/
private WindowsSecurityContextOptions windowsOptions;
public void setRunAsUser(Long runAsUser) {
this.runAsUser = runAsUser;
}
public Long getRunAsUser() {
return this.runAsUser;
}
public Long getRunAsGroup() {
return runAsGroup;
}
public void setRunAsGroup(Long runAsGroup) {
this.runAsGroup = runAsGroup;
}
public Boolean getRunAsNonRoot() {
return runAsNonRoot;
}
public void setRunAsNonRoot(Boolean runAsNonRoot) {
this.runAsNonRoot = runAsNonRoot;
}
public void setFsGroup(Long fsGroup) {
this.fsGroup = fsGroup;
}
public Long getFsGroup() {
return fsGroup;
}
public String getFsGroupChangePolicy() {
return fsGroupChangePolicy;
}
public void setFsGroupChangePolicy(String fsGroupChangePolicy) {
this.fsGroupChangePolicy = fsGroupChangePolicy;
}
public void setSupplementalGroups(Long[] supplementalGroups) {
this.supplementalGroups = supplementalGroups;
}
public Long[] getSupplementalGroups() {
return supplementalGroups;
}
public SeccompProfile getSeccompProfile() {
return seccompProfile;
}
public void setSeccompProfile(SeccompProfile seccompProfile) {
this.seccompProfile = seccompProfile;
}
public SELinuxOptions getSeLinuxOptions() {
return seLinuxOptions;
}
public void setSeLinuxOptions(SELinuxOptions seLinuxOptions) {
this.seLinuxOptions = seLinuxOptions;
}
public List<SysctlInfo> getSysctls() {
return sysctls;
}
public void setSysctls(List<SysctlInfo> sysctls) {
this.sysctls = sysctls;
}
public WindowsSecurityContextOptions getWindowsOptions() {
return windowsOptions;
}
public void setWindowsOptions(WindowsSecurityContextOptions windowsOptions) {
this.windowsOptions = windowsOptions;
}
}
public static class ContainerSecurityContext {
/**
* Whether a process can gain more privileges than its parent process
*/
private Boolean allowPrivilegeEscalation;
/**
* The capabilities to add/drop when running the container (cannot be set when spec.os.name is windows)
*/
private Capabilities capabilities;
/**
* Run container in privileged mode.
*/
private Boolean privileged;
/**
* The type of proc mount to use for the container (cannot be set when spec.os.name is windows)
*/
private String procMount;
/**
* Mounts the container's root filesystem as read-only
*/
private Boolean readOnlyRootFilesystem;
/**
* The numeric user ID to run pod container processes under
*/
private Long runAsUser;
/**
* The numeric group id to run the entrypoint of the container process
*/
private Long runAsGroup;
/**
* Indicates that the container must run as a non-root user
*/
private Boolean runAsNonRoot;
/**
* The seccomp options to use for the container
*/
private SeccompProfile seccompProfile;
/**
* The SELinux context to be applied to the container.
*/
private SELinuxOptions seLinuxOptions;
/**
* The Windows specific settings applied to the container.
*/
private WindowsSecurityContextOptions windowsOptions;
public Boolean getAllowPrivilegeEscalation() {
return allowPrivilegeEscalation;
}
public void setAllowPrivilegeEscalation(Boolean allowPrivilegeEscalation) {
this.allowPrivilegeEscalation = allowPrivilegeEscalation;
}
public Capabilities getCapabilities() {
return capabilities;
}
public void setCapabilities(Capabilities capabilities) {
this.capabilities = capabilities;
}
public Boolean getPrivileged() {
return privileged;
}
public void setPrivileged(Boolean privileged) {
this.privileged = privileged;
}
public String getProcMount() {
return procMount;
}
public void setProcMount(String procMount) {
this.procMount = procMount;
}
public Boolean getReadOnlyRootFilesystem() {
return readOnlyRootFilesystem;
}
public void setReadOnlyRootFilesystem(Boolean readOnlyRootFilesystem) {
this.readOnlyRootFilesystem = readOnlyRootFilesystem;
}
public Long getRunAsUser() {
return runAsUser;
}
public void setRunAsUser(Long runAsUser) {
this.runAsUser = runAsUser;
}
public Long getRunAsGroup() {
return runAsGroup;
}
public void setRunAsGroup(Long runAsGroup) {
this.runAsGroup = runAsGroup;
}
public Boolean getRunAsNonRoot() {
return runAsNonRoot;
}
public void setRunAsNonRoot(Boolean runAsNonRoot) {
this.runAsNonRoot = runAsNonRoot;
}
public SeccompProfile getSeccompProfile() {
return seccompProfile;
}
public void setSeccompProfile(SeccompProfile seccompProfile) {
this.seccompProfile = seccompProfile;
}
public SELinuxOptions getSeLinuxOptions() {
return seLinuxOptions;
}
public void setSeLinuxOptions(SELinuxOptions seLinuxOptions) {
this.seLinuxOptions = seLinuxOptions;
}
public WindowsSecurityContextOptions getWindowsOptions() {
return windowsOptions;
}
public void setWindowsOptions(WindowsSecurityContextOptions windowsOptions) {
this.windowsOptions = windowsOptions;
}
}
/**
* Adds and removes POSIX capabilities from running containers.
*/
public static class Capabilities {
/**
* Added capabilities.
*/
private List<String> add;
/**
* Removed capabilities.
*/
private List<String> drop;
public List<String> getAdd() {
return add;
}
public void setAdd(List<String> add) {
this.add = add;
}
public List<String> getDrop() {
return drop;
}
public void setDrop(List<String> drop) {
this.drop = drop;
}
}
/**
* Defines a pod seccomp profile settings.
*/
public static class SeccompProfile {
/**
* Type of seccomp profile.
*/
private String type;
/**
* Path of the pre-configured profile on the node, relative to the kubelet's configured Seccomp profile location, only valid when type is "Localhost".
*/
private String localhostProfile;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getLocalhostProfile() {
return localhostProfile;
}
public void setLocalhostProfile(String localhostProfile) {
this.localhostProfile = localhostProfile;
}
}
/**
* The labels to be applied to the container.
*/
public static class SELinuxOptions {
/**
* Level label applied to the container
*/
private String level;
/**
* Role Level label applied to the container
*/
private String role;
/**
* Type label applied to the container
*/
private String type;
/**
* User label applied to the container
*/
private String user;
public String getLevel() {
return level;
}
public void setLevel(String level) {
this.level = level;
}
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
}
/**
* Sysctl defines a kernel parameter to be set on the pod.
*/
public static class SysctlInfo {
/**
* Name of the property
*/
private String name;
/**
* Value of the property
*/
private String value;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
/**
* Contains Windows-specific options and credentials.
*/
public static class WindowsSecurityContextOptions {
/**
* Where the GMSA admission webhook inlines the contents of the GMSA credential spec
* named by the GMSACredentialSpecName field.
*/
private String gmsaCredentialSpec;
/**
* The name of the GMSA credential spec to use.
*/
private String gmsaCredentialSpecName;
/**
* Whether a container should be run as a 'Host Process' container.
*/
private Boolean hostProcess;
/**
* The username in Windows to run the entrypoint of the container process.
*/
private String runAsUserName;
public String getGmsaCredentialSpec() {
return gmsaCredentialSpec;
}
public void setGmsaCredentialSpec(String gmsaCredentialSpec) {
this.gmsaCredentialSpec = gmsaCredentialSpec;
}
public String getGmsaCredentialSpecName() {
return gmsaCredentialSpecName;
}
public void setGmsaCredentialSpecName(String gmsaCredentialSpecName) {
this.gmsaCredentialSpecName = gmsaCredentialSpecName;
}
public Boolean getHostProcess() {
return hostProcess;
}
public void setHostProcess(Boolean hostProcess) {
this.hostProcess = hostProcess;
}
public String getRunAsUserName() {
return runAsUserName;
}
public void setRunAsUserName(String runAsUserName) {
this.runAsUserName = runAsUserName;
}
}
public static class Lifecycle {
private Hook postStart;
private Hook preStop;
Hook getPreStop() {
return preStop;
}
Hook getPostStart() {
return postStart;
}
void setPostStart(Hook postStart) {
this.postStart = postStart;
}
void setPreStop(Hook preStop) {
this.preStop = preStop;
}
public static class Hook {
private Exec exec;
Exec getExec() {
return exec;
}
void setExec(Exec exec) {
this.exec = exec;
}
}
public static class Exec {
private List<String> command;
List<String> getCommand() {
return command;
}
void setCommand(List<String> command) {
this.command = command;
}
}
}
public static class InitContainer extends ContainerProperties {
}
static class Container extends io.fabric8.kubernetes.api.model.Container {
}
public static class ContainerProperties {
private String imageName;
private String containerName;
private List<String> commands;
private List<VolumeMount> volumeMounts;
/**
* Environment variables to set for any deployed init container.
*/
private String[] environmentVariables = new String[]{};
public String getImageName() {
return imageName;
}
public void setImageName(String imageName) {
this.imageName = imageName;
}
public String getContainerName() {
return containerName;
}
public void setContainerName(String containerName) {
this.containerName = containerName;
}
public List<String> getCommands() {
return commands;
}
public void setCommands(List<String> commands) {
this.commands = commands;
}
public List<VolumeMount> getVolumeMounts() {
return volumeMounts;
}
public void setVolumeMounts(List<VolumeMount> volumeMounts) {
this.volumeMounts = volumeMounts;
}
public String[] getEnvironmentVariables() {
return environmentVariables;
}
public void setEnvironmentVariables(String[] environmentVariables) {
this.environmentVariables = environmentVariables;
}
}
/**
* The {@link RestartPolicy} to use. Defaults to {@link RestartPolicy#Always}.
*/
private RestartPolicy restartPolicy = RestartPolicy.Always;
/**
* The default service account name to use for tasks.
*/
protected static final String DEFAULT_TASK_SERVICE_ACCOUNT_NAME = "default";
/**
* Service account name to use for tasks, defaults to:
* {@link #DEFAULT_TASK_SERVICE_ACCOUNT_NAME}
*/
private String taskServiceAccountName = DEFAULT_TASK_SERVICE_ACCOUNT_NAME;
/**
* Obtains the {@link RestartPolicy} to use. Defaults to
* {@link #restartPolicy}.
*
* @return the {@link RestartPolicy} to use
*/
public RestartPolicy getRestartPolicy() {
return restartPolicy;
}
/**
* Sets the {@link RestartPolicy} to use.
*
* @param restartPolicy the {@link RestartPolicy} to use
*/
public void setRestartPolicy(RestartPolicy restartPolicy) {
this.restartPolicy = restartPolicy;
}
/**
* Obtains the service account name to use for tasks.
*
* @return the service account name
*/
public String getTaskServiceAccountName() {
return taskServiceAccountName;
}
/**
* Sets the service account name to use for tasks.
*
* @param taskServiceAccountName the service account name
*/
public void setTaskServiceAccountName(String taskServiceAccountName) {
this.taskServiceAccountName = taskServiceAccountName;
}
/**
* Name of the environment variable that can define the Kubernetes namespace to use.
*/