From 1fe606cdf4f6dcdd6be8d8aaf8ae86e32d083c49 Mon Sep 17 00:00:00 2001 From: lauk001 Date: Fri, 23 Feb 2024 15:25:31 +0800 Subject: [PATCH] Supports multiple kubeadm api versions --- cmd/command/opts/opts.go | 34 ++++++------ cmd/command/setup_opts.go | 7 ++- data/assets_vfsdata.go | 12 ++--- .../files/etc/nkd/init-config.yaml.template | 10 ++-- .../files/etc/nkd/join-config.yaml.template | 2 +- pkg/configmanager/asset/clusterasset.go | 54 ++++++++++--------- pkg/ignition/common.go | 54 +++++++++---------- pkg/utils/utils.go | 25 +++++++++ 8 files changed, 112 insertions(+), 86 deletions(-) diff --git a/cmd/command/opts/opts.go b/cmd/command/opts/opts.go index 1589f9e..810427c 100644 --- a/cmd/command/opts/opts.go +++ b/cmd/command/opts/opts.go @@ -29,20 +29,21 @@ type OptionsList struct { ClusterID string Platform string - UserName string - Password string - SSHKey string - Master MasterConfig - Worker WorkerConfig - ExtendCount uint - Runtime string - ApiServerEndpoint string - ImageRegistry string - PauseImage string - ReleaseImageUrl string - KubeVersion string - Token string - CertificateKey string + UserName string + Password string + SSHKey string + Master MasterConfig + Worker WorkerConfig + ExtendCount uint + Runtime string + ApiServerEndpoint string + ImageRegistry string + PauseImage string + ReleaseImageUrl string + KubeVersion string + KubernetesAPIVersion uint + Token string + CertificateKey string NetWork NetworkConfig Housekeeper @@ -102,11 +103,6 @@ type NetworkConfig struct { ServiceSubnet string PodSubnet string Plugin string - DNS DnsConfig -} - -type DnsConfig struct { - ImageVersion string //coredns } type Housekeeper struct { diff --git a/cmd/command/setup_opts.go b/cmd/command/setup_opts.go index 4ec7052..6dd01fa 100644 --- a/cmd/command/setup_opts.go +++ b/cmd/command/setup_opts.go @@ -46,12 +46,16 @@ func SetupDeployCmdOpts(deployCmd *cobra.Command) { flags.StringVarP(&opts.Opts.PauseImage, "pause-image", "", "", "Specify the image for the pause container") flags.StringVarP(&opts.Opts.ReleaseImageUrl, "release-image-url", "", "", "Specify the URL of the NestOS container image that contains the Kubernetes component. Only supports the qcow2 format.") flags.StringVarP(&opts.Opts.KubeVersion, "kubeversion", "", "", "Specify the version of Kubernetes to deploy") + flags.UintVarP(&opts.Opts.KubernetesAPIVersion, "kubernetes-apiversion", "", 0, + "Sets the Kubernetes API version. Acceptable reference values:\n"+ + " - 1 for Kubernetes versions < v1.15.0,\n"+ + " - 2 for Kubernetes versions between v1.15.0 and v1.22.0,\n"+ + " - 3 for Kubernetes versions >= v1.22.0") flags.StringVarP(&opts.Opts.Token, "token", "", "", "Specify the authentication token for accessing resources") flags.StringVarP(&opts.Opts.CertificateKey, "CertificateKey", "", "", "Specifies the certificate key to be added to the master node") flags.StringVarP(&opts.Opts.NetWork.ServiceSubnet, "service-subnet", "", "", "Specify the subnet for Kubernetes services") flags.StringVarP(&opts.Opts.NetWork.PodSubnet, "pod-subnet", "", "", "Specify the subnet for Kubernetes Pods.") flags.StringVarP(&opts.Opts.NetWork.Plugin, "network-plugin-url", "", "", "URL for the network plugin") - flags.StringVarP(&opts.Opts.NetWork.DNS.ImageVersion, "image-version", "", "", "Specify the version of the CoreDNS container image") flags.StringVarP(&opts.Opts.Housekeeper.ControllerImageUrl, "controller-image-url", "", "", "Specify the URL of the container image for the housekeeper controller component") flags.StringVarP(&opts.Opts.Housekeeper.OperatorImageUrl, "operator-image-url", "", "", "Specify the URL of the container image for the housekeeper operator component") flags.BoolVarP(&opts.Opts.DeployHousekeeper, "deploy-housekeeper", "", false, "Deploy the Housekeeper Operator.") @@ -108,7 +112,6 @@ func SetupTemplateCmdOpts(templateCmd *cobra.Command) { flags.StringVarP(&opts.Opts.NetWork.ServiceSubnet, "service-subnet", "", "", "Specify the subnet for Kubernetes services") flags.StringVarP(&opts.Opts.NetWork.PodSubnet, "pod-subnet", "", "", "Specify the subnet for Kubernetes Pods.") flags.StringVarP(&opts.Opts.NetWork.Plugin, "network-plugin-url", "", "", "URL for the network plugin") - flags.StringVarP(&opts.Opts.NetWork.DNS.ImageVersion, "image-version", "", "", "Specify the version of the CoreDNS container image") flags.StringVarP(&opts.Opts.Housekeeper.ControllerImageUrl, "controller-image-url", "", "", "Specify the URL of the container image for the housekeeper controller component") flags.StringVarP(&opts.Opts.Housekeeper.OperatorImageUrl, "operator-image-url", "", "", "Specify the URL of the container image for the housekeeper operator component") flags.BoolVarP(&opts.Opts.DeployHousekeeper, "deploy-housekeeper", "", false, "Deploy the Housekeeper Operator.") diff --git a/data/assets_vfsdata.go b/data/assets_vfsdata.go index b568391..63bb0b2 100644 --- a/data/assets_vfsdata.go +++ b/data/assets_vfsdata.go @@ -106,10 +106,10 @@ var Assets = func() http.FileSystem { }, "/ignition/controlplane/files/etc/nkd/init-config.yaml.template": &vfsgen۰CompressedFileInfo{ name: "init-config.yaml.template", - modTime: time.Date(2024, 2, 23, 1, 13, 34, 763799970, time.UTC), - uncompressedSize: 911, + modTime: time.Date(2024, 2, 23, 7, 10, 51, 387036854, time.UTC), + uncompressedSize: 849, - compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x02\xff\xac\x51\x31\x6f\xe3\x3c\x0c\xdd\xf5\x2b\x04\xef\xb6\xfb\x15\xdf\x70\xd0\x56\xa4\x1d\x82\xde\x05\x41\xd2\xbb\x5d\xb6\x19\x55\xb0\x4c\x1a\x14\x9d\x4b\x60\xf8\xbf\x1f\x64\x3b\xbd\x66\xeb\x70\x93\xcd\xa7\xf7\xc8\xf7\x48\xdb\xfb\x5f\xc0\xd1\x13\x1a\xdd\x0e\x15\xd8\xa6\x2b\xda\x6f\xb1\xf0\x54\x9e\xff\xab\x40\xec\xa3\xaa\x88\x24\x0a\xdb\xfe\x8d\x5a\xc0\x68\x54\xae\x1d\xd3\xd0\x47\xa3\xb4\xce\x75\xbc\x46\x81\xce\x7c\xb0\x7a\xe0\x68\xd6\x56\xa6\x81\x93\x1d\x82\xe4\x48\x0d\xe4\x92\xf4\x4a\xeb\xf9\x6b\xf4\x38\x16\x73\xc7\x69\x4a\x98\x04\xa3\x1f\xff\x7f\x7f\xe8\x1e\xa2\xd2\x7a\x88\xd6\xc1\x6d\x80\x77\xe8\xd1\xcd\xff\x76\x90\x77\x40\xf1\xb5\x15\x4f\xa8\x5a\x8f\x8d\xd1\x5b\xf4\xb2\x21\x3c\x79\x37\xf0\x82\xa7\x71\x07\x70\x3e\x19\x4a\x40\x6a\x54\xb3\x3f\x52\xdd\x82\xcc\x93\x37\xb7\x6a\x9e\x8e\xb6\x83\x19\xde\x51\x03\x3b\xdb\xc1\x8c\xa6\x10\x01\xe4\xe5\x22\x6c\x9f\xd8\xcd\x76\xb4\x3e\x53\x18\x3a\xc8\xfb\x30\x38\x8f\x79\xe3\xd9\xe8\xac\xa4\x5e\xca\xe0\x2b\xb8\x40\x5d\x26\x19\x23\x08\xc4\x72\xed\xb0\x92\x63\xb9\x68\xcb\x99\x96\xa9\x1a\x58\xfc\x29\x65\x81\x57\xb8\x2e\xb6\xee\xa0\x69\x52\x79\x9e\xab\x2f\xdc\x68\x59\xc4\x26\x0c\x51\x80\xef\x77\x51\x13\x0a\x53\x08\xc0\x3f\x2c\x5a\x07\x9c\x62\xc0\x7d\xa6\x53\x80\x4b\xfe\xef\x82\xfd\x25\x7e\xf8\x1e\xc7\xe2\x75\xa8\x60\xad\xa7\x49\xf9\xce\x3a\x38\x40\x4f\xd1\x0b\xf1\x92\x7e\xbb\x60\xf3\xdd\x52\xf8\xd5\xfa\x3e\x58\x84\x17\x6c\x7a\xf2\x28\x46\x67\xe3\x58\x3c\xed\xb7\x47\xe0\x33\xf0\xcf\xc3\xf7\x69\xca\x14\x82\xfc\x26\x6e\x3d\xba\x14\x28\x02\x9f\x7d\x0d\xc7\xa1\x42\x58\x05\xc7\xcf\x50\x52\x68\xdd\x53\xf3\x99\xb1\xbf\x95\xcb\x6b\x83\xf1\x99\x3a\xeb\xd1\xe8\xac\x5e\xf6\x5a\x04\xaa\x6d\xc8\x54\x83\xf3\xda\xe4\xda\x83\xd1\x1b\x62\x78\xde\x1d\x95\xd6\x5f\x49\xb4\xb2\xde\xac\x5b\xce\x4d\x0c\x0d\xc6\xed\x8a\x4d\xd3\x9f\x00\x00\x00\xff\xff\x67\x94\x5d\xcf\x8f\x03\x00\x00"), + compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x02\xff\xac\x51\x41\x8f\x9b\x3c\x10\xbd\xf3\x2b\x2c\xee\xc0\xea\xd3\x77\xa8\x7c\x8b\xd2\x3d\x44\xdb\xae\xa2\xa4\xed\xdd\x81\x89\x77\x84\x99\x41\xe3\x21\xcd\x0a\xf1\xdf\x2b\x03\xc9\x6e\x8e\x95\x7a\x02\x3f\xbf\x37\xf3\xde\xb3\xeb\xf1\x17\x48\x44\x26\x6b\xda\xe1\x04\xae\xe9\xca\xf6\x4b\x2c\x91\xab\x71\x2c\x5f\x16\x64\x73\x27\x4d\x53\x76\x62\xd6\xa8\xe2\xfa\x1f\xdc\x02\x45\x9b\x15\xc6\x0b\x0f\x7d\xb4\x99\x31\x85\x89\xef\x51\xa1\xb3\x77\x56\x0f\x12\xed\x3a\xd9\x36\x70\x76\x43\xd0\x82\xb8\x81\x42\x93\x3e\x33\x66\xfe\x5a\x33\x8e\xe5\x3c\x71\x9a\x12\xa6\xc1\x9a\xff\xfe\x7f\x7b\xea\x9e\x62\x66\xcc\x10\x9d\x87\xdb\x02\xf4\x84\xe4\xe7\x7f\x37\xe8\x1b\x90\x62\xed\x14\x99\xb2\x16\xa9\xb1\x66\x47\xa8\x5b\xa6\x33\xfa\x41\x16\x3c\xad\x3b\x80\xc7\x64\x28\x01\x69\x50\x2d\x78\xe4\xba\x05\x9d\x37\x6f\x6f\xa7\x79\x3b\xb9\x0e\x66\xf8\x95\x1b\x78\x75\x1d\xcc\x68\x0a\x11\x40\x9f\xaf\x2a\x6e\x23\x7e\xb6\x63\xcc\x85\xc3\xd0\x41\xd1\x87\xc1\x23\x15\x0d\x8a\x35\x79\xc5\xbd\x56\x01\x4f\x70\x85\xba\x4a\x32\x21\x50\x88\xd5\x3a\x61\x25\xc7\x6a\xd1\x56\x33\x2d\xcf\x6a\x10\xc5\x73\xca\x02\x2f\xf0\xbe\xd8\x7a\x80\xa6\x29\x2b\x8a\x22\xfb\xfb\x27\x5b\x7a\xd9\x86\x21\x2a\xc8\x63\x35\x35\x93\x0a\x87\x00\xf2\xdd\x91\xf3\x20\x29\x15\x3c\x46\x3c\x07\xb8\x16\xff\x2e\xe7\x07\xf1\x1e\x63\xf5\xfd\xe1\x18\x3b\xe7\xe1\x00\x3d\x47\x54\x96\xa5\x8c\xdd\x82\xcd\xcf\x98\xba\x58\xad\xef\x83\x23\x78\xa6\xa6\x67\x24\xb5\x26\x1f\xc7\x72\xb3\xdf\x1d\x41\x2e\x20\x3f\x0f\xdf\xa6\x29\xcf\x08\xf4\x37\x4b\x8b\xe4\x53\xa0\x08\x72\xc1\x1a\x8e\xc3\x89\x60\x15\x1c\x3f\x43\x49\x61\x4c\xcf\xcd\x67\xc6\xfe\x76\x5c\x6e\x1b\x8a\x5f\xb9\x73\x48\xd6\xe4\xf5\xd2\x6b\x19\xb8\x76\x21\xff\x13\x00\x00\xff\xff\x05\xcc\x21\x0f\x51\x03\x00\x00"), }, "/ignition/controlplane/files/etc/nkd/node-pivot.sh.template": &vfsgen۰CompressedFileInfo{ name: "node-pivot.sh.template", @@ -333,10 +333,10 @@ var Assets = func() http.FileSystem { }, "/ignition/worker/files/etc/nkd/join-config.yaml.template": &vfsgen۰CompressedFileInfo{ name: "join-config.yaml.template", - modTime: time.Date(2024, 2, 23, 1, 13, 34, 764799980, time.UTC), - uncompressedSize: 334, + modTime: time.Date(2024, 2, 23, 7, 11, 44, 269974395, time.UTC), + uncompressedSize: 349, - compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x02\xff\x54\x8e\xc1\x6a\x2b\x31\x0c\x45\xf7\xfe\x0a\x7d\xc1\xcc\x7b\x85\x42\xf1\x2e\x1d\xba\x68\xe9\x22\x24\x6d\xf6\x8e\x47\x49\x85\x67\x24\x23\xcb\x03\x25\xe4\xdf\xcb\x38\x2d\xb4\x4b\x5d\xdd\x7b\x38\x21\xd3\x01\xb5\x90\xb0\x87\x54\x8f\x18\xc6\xb9\x4b\x0f\xa5\x23\xe9\x97\xff\x47\xb4\x70\xe7\x62\x18\x50\x6d\x1b\xec\xc3\x43\x8f\x16\xfb\xb5\xa7\x8c\x86\xa5\xcf\x89\xfa\x18\xba\xa8\xe6\x46\x2a\x51\x16\xd4\x4f\xef\x00\x8e\x22\x56\x4c\x43\x7e\x93\x84\xbc\x26\x00\x21\xd3\x1e\x75\x41\x7d\xe2\x31\x0b\xb1\x79\xb8\x5c\xba\xcd\xf6\xf9\x96\xbe\xef\x5e\xaf\xd7\x56\xb4\xb6\x59\x9f\x6d\xfd\x9d\x56\x2e\xe1\x84\xfb\x44\x79\xd8\x1c\x50\xe9\x44\x31\x58\xf3\x36\xad\xe8\x00\x8c\x66\x94\x6a\x1e\xee\xe7\x7f\x65\xbd\xa7\xf2\xf8\x57\xe3\x37\x32\x11\x8f\x1e\x5e\x84\x78\x10\x3e\xd1\xb9\x6a\xa3\x39\x96\x11\x77\x78\xa6\x75\xd6\xf0\x0e\x20\x2a\xed\x25\x26\xbc\x19\x0f\x3f\x57\x13\xb3\x40\x6c\xc5\x03\xd7\x69\x72\x5f\x01\x00\x00\xff\xff\xff\x84\xfc\x2a\x4e\x01\x00\x00"), + compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x02\xff\x54\x8f\xbd\x6e\xeb\x30\x0c\x85\x77\x3d\x05\x9f\xc0\xbe\xcb\x05\x0a\x6d\xa9\xd1\xa1\x3f\x43\x90\xb4\xd9\x15\x99\x49\x09\x25\xa4\x40\x51\x01\x0a\xc3\xef\x5e\x58\x6e\x8b\x76\xe4\xa7\xf3\x1d\x1c\x85\x4c\x07\xd4\x42\xc2\x1e\x52\x3d\x62\x18\xaf\x5d\xba\x2b\x1d\x49\x3f\x4d\xdd\xf3\x4a\x36\x3f\xa1\x79\x76\x31\x0c\xa8\xb6\x0d\xf6\xee\xa1\x47\x8b\xfd\xa2\x29\xa3\x61\xe9\x73\xa2\x3e\x86\x2e\xaa\xb9\x91\x4a\x94\x1b\xea\x87\x77\x00\x47\x11\x2b\xa6\x21\xbf\x4a\x42\x5e\x08\x40\xc8\xb4\x47\xbd\xa1\x3e\xf0\x98\x85\xd8\x3c\x4c\x53\xb7\xd9\x3e\xae\xf4\x6d\xf7\x32\xcf\x2d\x68\xcd\x59\x1e\x9b\xfd\x45\x2b\x97\x70\xc2\x7d\xa2\x3c\x6c\x0e\xa8\x74\xa2\x18\xac\x7d\xc3\xb4\xa2\x03\x30\xba\xa2\x54\xf3\xf0\xff\xfa\xaf\x2c\xf7\xa5\xdc\xff\x9d\xf1\xbb\x32\x11\x8f\x1e\x9e\x84\x78\x10\x3e\xd1\xb9\x6a\x6b\x73\x2c\x23\xee\xf0\x4c\x8b\xd6\xea\x1d\x40\x54\xda\x4b\x4c\xb8\x2e\x1e\xbe\xaf\x36\xcc\x02\xb1\x15\x0f\x5c\x2f\x17\xf7\x19\x00\x00\xff\xff\xde\x29\x29\x8e\x5d\x01\x00\x00"), }, "/ignition/worker/files/etc/nkd/node-pivot.sh.template": &vfsgen۰CompressedFileInfo{ name: "node-pivot.sh.template", diff --git a/data/data/ignition/controlplane/files/etc/nkd/init-config.yaml.template b/data/data/ignition/controlplane/files/etc/nkd/init-config.yaml.template index 183a64c..3f724e1 100644 --- a/data/data/ignition/controlplane/files/etc/nkd/init-config.yaml.template +++ b/data/data/ignition/controlplane/files/etc/nkd/init-config.yaml.template @@ -1,4 +1,4 @@ -apiVersion: kubeadm.k8s.io/v1beta2 +apiVersion: kubeadm.k8s.io/{{.KubeadmApiVersion}} bootstrapTokens: - groups: - system:bootstrappers:kubeadm:default-node-token @@ -15,7 +15,7 @@ nodeRegistration: volume-plugin-dir: "/opt/libexec/kubernetes/kubelet-plugins/volume/exec/" certificateKey: {{.CertificateKey}} --- -apiVersion: kubeadm.k8s.io/v1beta2 +apiVersion: kubeadm.k8s.io/{{.KubeadmApiVersion}} kind: ClusterConfiguration controllerManager: extraArgs: @@ -26,8 +26,4 @@ controlPlaneEndpoint: "{{.APIServerURL}}" networking: serviceSubnet: "{{.ServiceSubnet}}" podSubnet: "{{.PodSubnet}}" - dnsDomain: "cluster.local" -dns: - type: CoreDNS - imageRepository: {{.ImageRegistry}} - imageTag: {{.CorednsImageTag}} \ No newline at end of file + dnsDomain: "cluster.local" \ No newline at end of file diff --git a/data/data/ignition/worker/files/etc/nkd/join-config.yaml.template b/data/data/ignition/worker/files/etc/nkd/join-config.yaml.template index b14be5b..de20e45 100644 --- a/data/data/ignition/worker/files/etc/nkd/join-config.yaml.template +++ b/data/data/ignition/worker/files/etc/nkd/join-config.yaml.template @@ -1,4 +1,4 @@ -apiVersion: kubeadm.k8s.io/v1beta2 +apiVersion: kubeadm.k8s.io/{{.KubeadmApiVersion}} caCertPath: /etc/kubernetes/pki/ca.crt discovery: bootstrapToken: diff --git a/pkg/configmanager/asset/clusterasset.go b/pkg/configmanager/asset/clusterasset.go index 1843828..53492a4 100644 --- a/pkg/configmanager/asset/clusterasset.go +++ b/pkg/configmanager/asset/clusterasset.go @@ -25,6 +25,7 @@ import ( "time" "github.com/pkg/errors" + "github.com/sirupsen/logrus" "gopkg.in/yaml.v2" ) @@ -167,23 +168,23 @@ type InfraPlatform interface { } type Kubernetes struct { - Kubernetes_Version string - ApiServer_Endpoint string - Image_Registry string - Pause_Image string - Release_Image_URL string - Token string - AdminKubeConfig string - CertificateKey string + Kubernetes_Version string + KubernetesAPIVersion string `yaml:"kubernetes-apiversion"` + ApiServer_Endpoint string + Image_Registry string + Pause_Image string + Release_Image_URL string + Token string + AdminKubeConfig string + CertificateKey string Network } type Network struct { - Service_Subnet string - Pod_Subnet string - Plugin string - CoreDNS_Image_Version string + Service_Subnet string + Pod_Subnet string + Plugin string } type Housekeeper struct { @@ -282,7 +283,12 @@ func (clusterAsset *ClusterAsset) InitClusterAsset(infraAsset InfraAsset, opts * setStringValue(&clusterAsset.Kubernetes.Network.Service_Subnet, opts.NetWork.ServiceSubnet, cf.Service_Subnet) setStringValue(&clusterAsset.Kubernetes.Network.Pod_Subnet, opts.NetWork.PodSubnet, cf.Network.Pod_Subnet) setStringValue(&clusterAsset.Kubernetes.Network.Plugin, opts.NetWork.Plugin, cf.Network.Plugin) - setStringValue(&clusterAsset.Kubernetes.Network.CoreDNS_Image_Version, opts.NetWork.DNS.ImageVersion, cf.Network.CoreDNS_Image_Version) + apiVersion, err := utils.GetKubernetesApiVersion(opts.KubernetesAPIVersion) + if err != nil { + logrus.Errorf("Error getting kubernetes api version: %v\n", err) + return nil, err + } + setStringValue(&clusterAsset.Kubernetes.KubernetesAPIVersion, apiVersion, cf.KubernetesAPIVersion) if clusterAsset.Housekeeper.DeployHousekeeper || opts.Housekeeper.DeployHousekeeper { setStringValue(&clusterAsset.Housekeeper.OperatorImageUrl, opts.Housekeeper.OperatorImageUrl, cf.OperatorImageUrl) @@ -364,18 +370,18 @@ func GetDefaultClusterConfig(arch string) (*ClusterAsset, error) { }, Runtime: "isulad", Kubernetes: Kubernetes{ - Kubernetes_Version: "v1.23.10", - ApiServer_Endpoint: utils.GetApiServerEndpoint("192.168.132.11"), - Image_Registry: "k8s.gcr.io", - Pause_Image: "pause:3.6", - Release_Image_URL: "", - Token: generateToken(), - CertificateKey: "a301c9c55596c54c5d4c7173aa1e3b6fd304130b0c703bb23149c0c69f94b8e0", + Kubernetes_Version: "v1.23.10", + KubernetesAPIVersion: "v1beta3", + ApiServer_Endpoint: utils.GetApiServerEndpoint("192.168.132.11"), + Image_Registry: "k8s.gcr.io", + Pause_Image: "pause:3.6", + Release_Image_URL: "", + Token: generateToken(), + CertificateKey: "a301c9c55596c54c5d4c7173aa1e3b6fd304130b0c703bb23149c0c69f94b8e0", Network: Network{ - Service_Subnet: "10.96.0.0/16", - Pod_Subnet: "10.244.0.0/16", - Plugin: "https://projectcalico.docs.tigera.io/archive/v3.22/manifests/calico.yaml", - CoreDNS_Image_Version: "v1.8.6", + Service_Subnet: "10.96.0.0/16", + Pod_Subnet: "10.244.0.0/16", + Plugin: "https://projectcalico.docs.tigera.io/archive/v3.22/manifests/calico.yaml", }, }, Housekeeper: Housekeeper{ diff --git a/pkg/ignition/common.go b/pkg/ignition/common.go index 646c0ce..7f9b980 100644 --- a/pkg/ignition/common.go +++ b/pkg/ignition/common.go @@ -41,20 +41,20 @@ var ( ) type TmplData struct { - NodeName string - APIServerURL string - ImageRegistry string - Runtime string - CriSocket string - PauseImage string - KubeVersion string - ServiceSubnet string - PodSubnet string - Token string - CorednsImageTag string - ReleaseImageURl string - CertificateKey string - Hsip string //HostName + IP + NodeName string + APIServerURL string + ImageRegistry string + Runtime string + CriSocket string + PauseImage string + KubeVersion string + ServiceSubnet string + PodSubnet string + Token string + ReleaseImageURl string + CertificateKey string + Hsip string //HostName + IP + KubeadmApiVersion string } type Common struct { @@ -214,18 +214,18 @@ func GetTmplData(c *asset.ClusterAsset) (*TmplData, error) { } return &TmplData{ - APIServerURL: c.Kubernetes.ApiServer_Endpoint, - ImageRegistry: c.Kubernetes.Image_Registry, - Runtime: c.Runtime, - CriSocket: criSocket, - PauseImage: c.Kubernetes.Pause_Image, - KubeVersion: c.Kubernetes.Kubernetes_Version, - ServiceSubnet: c.Network.Service_Subnet, - PodSubnet: c.Network.Pod_Subnet, - Token: c.Kubernetes.Token, - CorednsImageTag: c.Network.CoreDNS_Image_Version, - ReleaseImageURl: c.Kubernetes.Release_Image_URL, - CertificateKey: c.Kubernetes.CertificateKey, - Hsip: hsip, + APIServerURL: c.Kubernetes.ApiServer_Endpoint, + ImageRegistry: c.Kubernetes.Image_Registry, + Runtime: c.Runtime, + CriSocket: criSocket, + PauseImage: c.Kubernetes.Pause_Image, + KubeVersion: c.Kubernetes.Kubernetes_Version, + KubeadmApiVersion: c.Kubernetes.KubernetesAPIVersion, + ServiceSubnet: c.Network.Service_Subnet, + PodSubnet: c.Network.Pod_Subnet, + Token: c.Kubernetes.Token, + ReleaseImageURl: c.Kubernetes.Release_Image_URL, + CertificateKey: c.Kubernetes.CertificateKey, + Hsip: hsip, }, nil } diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index a2f80ef..2cf807e 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -24,6 +24,31 @@ import ( "strings" ) +type version uint + +const ( + v1beta1 version = iota + 1 + v1beta2 + v1beta3 +) + +var versionMap = map[version]string{ + v1beta1: "v1beta1", + v1beta2: "v1beta2", + v1beta3: "v1beta3", +} + +func GetKubernetesApiVersion(versionNumber uint) (string, error) { + if versionNumber == 0 { + return "", nil + } + v := version(versionNumber) + if str, ok := versionMap[v]; ok { + return str, nil + } + return "", fmt.Errorf("unsupported kubernetes api version number: %d", versionNumber) +} + func GetDefaultPubKeyPath() string { return filepath.Join(getSysHome(), ".ssh", "id_rsa.pub") } -- Gitee