@@ -13,6 +13,7 @@ import (
1313 "time"
1414 "unicode"
1515
16+ "github.com/kubean-io/kubean/pkg/crypto"
1617 "github.com/kubean-io/kubean/pkg/util"
1718 "github.com/kubean-io/kubean/pkg/util/entrypoint"
1819
@@ -382,14 +383,26 @@ func (c *Controller) NewKubesprayJob(clusterOps *clusteroperationv1alpha1.Cluste
382383 ServiceAccountName : serviceAccountName ,
383384 Containers : []corev1.Container {
384385 {
385- Name : SprayJobPodName ,
386- Image : c .ProcessKubeanOperationImage (clusterOps .Spec .Image , c .FetchGlobalManifestImageTag ()),
387- Command : []string {"/bin/entrypoint.sh" },
386+ Name : SprayJobPodName ,
387+ Image : c .ProcessKubeanOperationImage (clusterOps .Spec .Image , c .FetchGlobalManifestImageTag ()),
388+ ImagePullPolicy : corev1 .PullIfNotPresent ,
389+ Command : []string {"/bin/entrypoint.sh" },
388390 Env : []corev1.EnvVar {
389391 {
390392 Name : "CLUSTER_NAME" ,
391393 Value : clusterOps .Spec .Cluster ,
392394 },
395+ {
396+ Name : "VAULT_PRIVATE_KEY" ,
397+ ValueFrom : & corev1.EnvVarSource {
398+ ConfigMapKeyRef : & corev1.ConfigMapKeySelector {
399+ LocalObjectReference : corev1.LocalObjectReference {
400+ Name : constants .KubeanConfigMapName ,
401+ },
402+ Key : crypto .PrivateKey ,
403+ },
404+ },
405+ },
393406 },
394407 VolumeMounts : []corev1.VolumeMount {
395408 {
@@ -480,27 +493,6 @@ func (c *Controller) NewKubesprayJob(clusterOps *clusteroperationv1alpha1.Cluste
480493 },
481494 })
482495 }
483- if vaultRef := c .getVaultSecret (clusterOps ); vaultRef != nil {
484- if len (job .Spec .Template .Spec .Containers ) > 0 && job .Spec .Template .Spec .Containers [0 ].Name == SprayJobPodName {
485- job .Spec .Template .Spec .Containers [0 ].VolumeMounts = append (job .Spec .Template .Spec .Containers [0 ].VolumeMounts ,
486- corev1.VolumeMount {
487- Name : "vault-password" ,
488- MountPath : "/auth/vault-password" ,
489- SubPath : "vault-password" ,
490- ReadOnly : true ,
491- })
492- }
493- job .Spec .Template .Spec .Volumes = append (job .Spec .Template .Spec .Volumes ,
494- corev1.Volume {
495- Name : "vault-password" ,
496- VolumeSource : corev1.VolumeSource {
497- Secret : & corev1.SecretVolumeSource {
498- SecretName : vaultRef .Name ,
499- DefaultMode : & PrivatekeyMode ,
500- },
501- },
502- })
503- }
504496 if clusterOps .Spec .ActiveDeadlineSeconds != nil && * clusterOps .Spec .ActiveDeadlineSeconds > 0 {
505497 job .Spec .ActiveDeadlineSeconds = clusterOps .Spec .ActiveDeadlineSeconds
506498 }
@@ -638,7 +630,8 @@ func (c *Controller) CreateEntryPointShellConfigMap(clusterOps *clusteroperation
638630 if ! clusterOps .Spec .EntrypointSHRef .IsEmpty () {
639631 return false , nil
640632 }
641- entryPointData := entrypoint .NewEntryPoint (c .getVaultSecret (clusterOps ) != nil )
633+
634+ entryPointData := entrypoint .NewEntryPoint ()
642635 isPrivateKey := ! clusterOps .Spec .SSHAuthRef .IsEmpty ()
643636 builtinActionSource := clusteroperationv1alpha1 .BuiltinActionSource
644637 for _ , action := range clusterOps .Spec .PreHook {
@@ -798,9 +791,8 @@ func (c *Controller) CopyConfigMap(clusterOps *clusteroperationv1alpha1.ClusterO
798791 APIVersion : "v1" ,
799792 },
800793 ObjectMeta : metav1.ObjectMeta {
801- Name : newName ,
802- Namespace : namespace ,
803- Annotations : oldConfigMap .Annotations ,
794+ Name : newName ,
795+ Namespace : namespace ,
804796 },
805797 Data : oldConfigMap .Data ,
806798 }
@@ -1010,25 +1002,3 @@ func (c *Controller) CheckClusterDataRef(cluster *clusterv1alpha1.Cluster, clust
10101002 }
10111003 return nil
10121004}
1013-
1014- func (c * Controller ) getVaultSecret (clusterOps * clusteroperationv1alpha1.ClusterOperation ) * apis.SecretRef {
1015- if clusterOps .Spec .HostsConfRef .IsEmpty () {
1016- return nil
1017- }
1018- hostsConf , err := c .ClientSet .CoreV1 ().ConfigMaps (clusterOps .Spec .HostsConfRef .NameSpace ).Get (context .Background (), clusterOps .Spec .HostsConfRef .Name , metav1.GetOptions {})
1019- if err != nil {
1020- return nil
1021- }
1022- vaultRef , ok := hostsConf .Annotations [constants .AnnotationHostsConfVaultPasswordRef ]
1023- if ! ok || vaultRef == "" {
1024- return nil
1025- }
1026- if ! c .CheckSecretExist (util .GetCurrentNSOrDefault (), vaultRef ) {
1027- klog .Warningf ("vault password ref %s not found in namespace %s" , vaultRef , util .GetCurrentNSOrDefault ())
1028- return nil
1029- }
1030- return & apis.SecretRef {
1031- NameSpace : util .GetCurrentNSOrDefault (),
1032- Name : vaultRef ,
1033- }
1034- }
0 commit comments