From ee6c1ff9570830d28d217945dd8e0455efa5a4b1 Mon Sep 17 00:00:00 2001 From: lauk001 Date: Thu, 7 Sep 2023 18:54:15 +0800 Subject: [PATCH] adjust the ignition profile of the worker node --- app/apis/nkd/const.go | 2 +- app/cmd/phases/config/print.go | 1 + app/cmd/phases/initconfig/ign.go | 18 +++++++++--------- .../worker/files/etc/hostname.template | 1 - 4 files changed, 11 insertions(+), 11 deletions(-) delete mode 100644 data/ignition/worker/files/etc/hostname.template diff --git a/app/apis/nkd/const.go b/app/apis/nkd/const.go index 6d37072..d4037b1 100644 --- a/app/apis/nkd/const.go +++ b/app/apis/nkd/const.go @@ -25,7 +25,7 @@ var ( MasterHostName = "master" WorkerHostName = "worker" Username = "root" - Password = "" + Password = "$1$yoursalt$UGhjCXAJKpWWpeN8xsF.c/" // repo Secret = []map[string]string{{"repousre": ""}} diff --git a/app/cmd/phases/config/print.go b/app/cmd/phases/config/print.go index d2b06a6..570af16 100644 --- a/app/cmd/phases/config/print.go +++ b/app/cmd/phases/config/print.go @@ -114,6 +114,7 @@ func DefaultedStaticWorkerConfiguration(internalconfig *nkd.Worker) *nkd.Worker system1 := nkd.System{ Count: nkd.Worker_Count, + Ips: nkd.Openstack_Master_ip, WorkerHostName: nkd.WorkerHostName, MasterHostName: nkd.MasterHostName, Username: nkd.Username, diff --git a/app/cmd/phases/initconfig/ign.go b/app/cmd/phases/initconfig/ign.go index 82c10dd..a6c867a 100644 --- a/app/cmd/phases/initconfig/ign.go +++ b/app/cmd/phases/initconfig/ign.go @@ -58,6 +58,7 @@ type commonTemplateData struct { CorednsImageTag string IpSegment string ReleaseImageURl string + PasswordHash string } var ( @@ -105,18 +106,15 @@ func runGenerateIgnConfig(r workflow.RunData, node string) error { } } } else { - nodeCount = data.WorkerCfg().System.Count hostName = data.WorkerCfg().System.MasterHostName for i := 0; i < len(data.WorkerCfg().System.Ips); i++ { oneNodeName = fmt.Sprintf("%s%02d", hostName, i+1) temp := data.WorkerCfg().System.Ips[i] + " " + oneNodeName + "\n" hsip = hsip + temp } - for j := 0; j < nodeCount; j++ { - ctd := getWorkerTmplData(data.WorkerCfg(), j+1, hsip) - if err := generateConfig(ctd); err != nil { - return err - } + ctd := getWorkerTmplData(data.WorkerCfg(), hsip) + if err := generateConfig(ctd); err != nil { + return err } } return nil @@ -138,11 +136,11 @@ func getMasterTmplData(nkdConfig *nkd.Master, count int, ip string, hsip string) CorednsImageTag: nkdConfig.ContainerDaemon.CorednsImageTag, IpSegment: ip, ReleaseImageURl: nkdConfig.ContainerDaemon.ReleaseImageURl, + PasswordHash: nkdConfig.System.Password, } } -func getWorkerTmplData(nkdConfig *nkd.Worker, count int, hsip string) *commonTemplateData { - oneNodeName := fmt.Sprintf("%s%d", nkdConfig.System.WorkerHostName, count) +func getWorkerTmplData(nkdConfig *nkd.Worker, hsip string) *commonTemplateData { return &commonTemplateData{ SSHKey: nkdConfig.System.SSHKey, APIServerURL: nkdConfig.Worker.Discovery.BootstrapToken.APIServerEndpoint, @@ -150,9 +148,10 @@ func getWorkerTmplData(nkdConfig *nkd.Worker, count int, hsip string) *commonTem ImageRegistry: nkdConfig.Repo.Registry, PauseImageTag: nkdConfig.ContainerDaemon.PauseImageTag, Token: nkdConfig.Worker.Discovery.TlsBootstrapToken, - NodeName: oneNodeName, + NodeName: nkdConfig.System.WorkerHostName, NodeType: "worker", ReleaseImageURl: nkdConfig.ContainerDaemon.ReleaseImageURl, + PasswordHash: nkdConfig.System.Password, } } @@ -168,6 +167,7 @@ func generateConfig(ctd *commonTemplateData) error { SSHAuthorizedKeys: []igntypes.SSHAuthorizedKey{ igntypes.SSHAuthorizedKey(ctd.SSHKey), }, + PasswordHash: &ctd.PasswordHash, Groups: []igntypes.Group{ igntypes.Group("adm"), igntypes.Group("sudo"), diff --git a/data/ignition/worker/files/etc/hostname.template b/data/ignition/worker/files/etc/hostname.template deleted file mode 100644 index f073774..0000000 --- a/data/ignition/worker/files/etc/hostname.template +++ /dev/null @@ -1 +0,0 @@ -{{.NodeName}} \ No newline at end of file -- Gitee