Skip to content

Commit

Permalink
Add support for ARM64
Browse files Browse the repository at this point in the history
  • Loading branch information
Ciprian Hacman committed Jun 5, 2020
1 parent 9e4bf16 commit 102e2a2
Show file tree
Hide file tree
Showing 16 changed files with 242 additions and 131 deletions.
6 changes: 6 additions & 0 deletions pkg/apis/kops/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,12 @@ func (c *Cluster) IsKubernetesGTE(version string) bool {
return clusterVersion.GTE(*parsedVersion)
}

// IsKubernetesLT checks if the version is < the specified version.
// It panics if the kubernetes version in the cluster is invalid, or if the version is invalid.
func (c *Cluster) IsKubernetesLT(version string) bool {
return !c.IsKubernetesGTE(version)
}

// EnvVar represents an environment variable present in a Container.
type EnvVar struct {
// Name of the environment variable. Must be a C_IDENTIFIER.
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/nodeup/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ go_library(
srcs = ["config.go"],
importpath = "k8s.io/kops/pkg/apis/nodeup",
visibility = ["//visibility:public"],
deps = ["//util/pkg/architectures:go_default_library"],
)
8 changes: 6 additions & 2 deletions pkg/apis/nodeup/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@ limitations under the License.

package nodeup

import (
"k8s.io/kops/util/pkg/architectures"
)

// Config is the configuration for the nodeup binary
type Config struct {
// Tags enable/disable chunks of the model
Tags []string `json:",omitempty"`
// Assets are locations where we can find files to be installed
// TODO: Remove once everything is in containers?
Assets []string `json:",omitempty"`
Assets map[architectures.Architecture][]string `json:",omitempty"`
// Images are a list of images we should preload
Images []*Image `json:"images,omitempty"`
Images map[architectures.Architecture][]*Image `json:"images,omitempty"`
// ConfigBase is the base VFS path for config objects
ConfigBase *string `json:",omitempty"`
// ClusterLocation is the VFS path to the cluster spec (deprecated: prefer ConfigBase)
Expand Down
1 change: 1 addition & 0 deletions pkg/bundle/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ go_library(
"//upup/pkg/fi:go_default_library",
"//upup/pkg/fi/cloudup:go_default_library",
"//upup/pkg/fi/utils:go_default_library",
"//util/pkg/architectures:go_default_library",
"//util/pkg/vfs:go_default_library",
"//vendor/k8s.io/klog:go_default_library",
],
Expand Down
17 changes: 13 additions & 4 deletions pkg/bundle/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"k8s.io/kops/upup/pkg/fi"
"k8s.io/kops/upup/pkg/fi/cloudup"
"k8s.io/kops/upup/pkg/fi/utils"
"k8s.io/kops/util/pkg/architectures"
"k8s.io/kops/util/pkg/vfs"
)

Expand Down Expand Up @@ -172,13 +173,21 @@ func (b *Builder) Build(cluster *kops.Cluster, ig *kops.InstanceGroup) (*Data, e
bootstrapScript := model.BootstrapScript{}

{
asset, err := cloudup.NodeUpAsset(assetBuilder)
assetAmd64, err := cloudup.NodeUpAsset(assetBuilder, architectures.ArchitectureAmd64)
if err != nil {
return nil, err
}

bootstrapScript.NodeUpSource = strings.Join(asset.Locations, ",")
bootstrapScript.NodeUpSourceHash = asset.Hash.Hex()
bootstrapScript.NodeUpSourceAmd64 = strings.Join(assetAmd64.Locations, ",")
bootstrapScript.NodeUpSourceHashAmd64 = assetAmd64.Hash.Hex()

if cluster.IsKubernetesGTE("1.19") {
assetArm64, err := cloudup.NodeUpAsset(assetBuilder, architectures.ArchitectureArm64)
if err != nil {
return nil, err
}
bootstrapScript.NodeUpSourceArm64 = strings.Join(assetArm64.Locations, ",")
bootstrapScript.NodeUpSourceHashArm64 = assetArm64.Hash.Hex()
}
}

bootstrapScript.NodeUpConfigBuilder = func(ig *kops.InstanceGroup) (*nodeup.Config, error) {
Expand Down
22 changes: 15 additions & 7 deletions pkg/model/bootstrapscript.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ import (

// BootstrapScript creates the bootstrap script
type BootstrapScript struct {
NodeUpSource string
NodeUpSourceHash string
NodeUpConfigBuilder func(ig *kops.InstanceGroup) (*nodeup.Config, error)
NodeUpSourceAmd64 string
NodeUpSourceHashAmd64 string
NodeUpSourceArm64 string
NodeUpSourceHashArm64 string
NodeUpConfigBuilder func(ig *kops.InstanceGroup) (*nodeup.Config, error)
}

// KubeEnv returns the nodeup config for the instance group
Expand Down Expand Up @@ -140,11 +142,17 @@ func (b *BootstrapScript) ResourceNodeUp(ig *kops.InstanceGroup, cluster *kops.C
}

functions := template.FuncMap{
"NodeUpSource": func() string {
return b.NodeUpSource
"NodeUpSourceAmd64": func() string {
return b.NodeUpSourceAmd64
},
"NodeUpSourceHash": func() string {
return b.NodeUpSourceHash
"NodeUpSourceHashAmd64": func() string {
return b.NodeUpSourceHashAmd64
},
"NodeUpSourceArm64": func() string {
return b.NodeUpSourceArm64
},
"NodeUpSourceHashArm64": func() string {
return b.NodeUpSourceHashArm64
},
"KubeEnv": func() (string, error) {
return b.KubeEnv(ig)
Expand Down
8 changes: 5 additions & 3 deletions pkg/model/bootstrapscript_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,11 @@ func TestBootstrapUserData(t *testing.T) {
}

bs := &BootstrapScript{
NodeUpSource: "NUSource",
NodeUpSourceHash: "NUSHash",
NodeUpConfigBuilder: renderNodeUpConfig,
NodeUpSourceAmd64: "NUSourceAmd64",
NodeUpSourceHashAmd64: "NUSHashAmd64",
NodeUpSourceArm64: "NUSourceArm64",
NodeUpSourceHashArm64: "NUSHashArm64",
NodeUpConfigBuilder: renderNodeUpConfig,
}

// Purposely running this twice to cover issue #3516
Expand Down
12 changes: 8 additions & 4 deletions pkg/model/openstackmodel/servergroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2715,8 +2715,10 @@ func Test_ServerGroupModelBuilder(t *testing.T) {
NodeUpConfigBuilder: func(ig *kops.InstanceGroup) (*nodeup.Config, error) {
return &nodeup.Config{}, nil
},
NodeUpSource: "source",
NodeUpSourceHash: "source-hash",
NodeUpSourceAmd64: "source-amd64",
NodeUpSourceHashAmd64: "source-hash-amd64",
NodeUpSourceArm64: "source-arm64",
NodeUpSourceHashArm64: "source-hash-arm64",
}

builder := createBuilderForCluster(testCase.cluster, testCase.instanceGroups, clusterLifecycle, bootstrapScriptBuilder)
Expand Down Expand Up @@ -3179,8 +3181,10 @@ func mustUserdataForClusterInstance(cluster *kops.Cluster, ig *kops.InstanceGrou
NodeUpConfigBuilder: func(ig *kops.InstanceGroup) (*nodeup.Config, error) {
return &nodeup.Config{}, nil
},
NodeUpSource: "source",
NodeUpSourceHash: "source-hash",
NodeUpSourceAmd64: "source-amd64",
NodeUpSourceHashAmd64: "source-hash-amd64",
NodeUpSourceArm64: "source-arm64",
NodeUpSourceHashArm64: "source-hash-arm64",
}
startupResources, err := bootstrapScriptBuilder.ResourceNodeUp(ig, cluster)
if err != nil {
Expand Down
14 changes: 10 additions & 4 deletions pkg/model/resources/nodeup.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ set -o errexit
set -o nounset
set -o pipefail
NODEUP_URL={{ NodeUpSource }}
NODEUP_HASH={{ NodeUpSourceHash }}
NODEUP_URL_AMD64={{ NodeUpSourceAmd64 }}
NODEUP_HASH_AMD64={{ NodeUpSourceHashAmd64 }}
NODEUP_URL_ARM64={{ NodeUpSourceArm64 }}
NODEUP_HASH_ARM64={{ NodeUpSourceHashArm64 }}
{{ EnvironmentVariables }}
Expand Down Expand Up @@ -139,8 +141,12 @@ function try-download-release() {
function download-release() {
case "$(uname -m)" in
x86_64*|i?86_64*|amd64*)
NODEUP_URL="${NODEUP_URL}"
NODEUP_HASH="${NODEUP_HASH}"
NODEUP_URL="${NODEUP_URL_AMD64}"
NODEUP_HASH="${NODEUP_HASH_AMD64}"
;;
aarch64*|arm64*)
NODEUP_URL="${NODEUP_URL_ARM64}"
NODEUP_HASH="${NODEUP_HASH_ARM64}"
;;
*)
echo "Unsupported host arch: $(uname -m)" >&2
Expand Down
2 changes: 2 additions & 0 deletions upup/pkg/fi/cloudup/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ go_library(
"//upup/pkg/fi/fitasks:go_default_library",
"//upup/pkg/fi/loader:go_default_library",
"//upup/pkg/fi/utils:go_default_library",
"//util/pkg/architectures:go_default_library",
"//util/pkg/env:go_default_library",
"//util/pkg/hashing:go_default_library",
"//util/pkg/reflectutils:go_default_library",
Expand Down Expand Up @@ -125,6 +126,7 @@ go_test(
"//upup/pkg/fi:go_default_library",
"//upup/pkg/fi/cloudup/awsup:go_default_library",
"//upup/pkg/fi/fitasks:go_default_library",
"//util/pkg/architectures:go_default_library",
"//util/pkg/vfs:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library",
"//vendor/k8s.io/klog:go_default_library",
Expand Down
Loading

0 comments on commit 102e2a2

Please sign in to comment.