Skip to content

Commit

Permalink
ARM64 support - Build multi-arch images
Browse files Browse the repository at this point in the history
  • Loading branch information
Ciprian Hacman committed Jul 14, 2020
1 parent 7a61e9f commit 9d8decf
Show file tree
Hide file tree
Showing 13 changed files with 281 additions and 230 deletions.
117 changes: 74 additions & 43 deletions Makefile

Large diffs are not rendered by default.

59 changes: 32 additions & 27 deletions cmd/kops-controller/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -33,48 +33,53 @@ go_binary(
load(
"@io_bazel_rules_docker//container:container.bzl",
"container_image",
"container_push",
"container_bundle",
"container_push",
)

container_image(
name = "image",
ARCH = [
"amd64",
"arm64",
]

[container_image(
name = "image-%s" % arch,
architecture = arch,
base = "@distroless_base//image",
cmd = ["/usr/bin/kops-controller"],
cmd = ["/kops-controller"],
user = "10001",
directory = "/usr/bin/",
files = [
"//cmd/kops-controller",
],
stamp = True,
)

container_push(
name = "push-image",
format = "Docker",
image = ":image",
registry = "{STABLE_DOCKER_REGISTRY}",
repository = "{STABLE_DOCKER_IMAGE_PREFIX}kops-controller",
tag = "{STABLE_KOPS_CONTROLLER_TAG}",
)
) for arch in ARCH]

container_bundle(
name = "image-bundle",
[container_bundle(
name = "image-bundle-%s" % arch,
images = {
"{STABLE_DOCKER_IMAGE_PREFIX}kops-controller:{STABLE_KOPS_CONTROLLER_TAG}": "image",
"{STABLE_DOCKER_IMAGE_PREFIX}kops-controller:{STABLE_KOPS_CONTROLLER_TAG}": "image-%s" % arch,
},
)
) for arch in ARCH]

load("//tools:gzip.bzl", "gzip")

gzip(
name = "image-bundle.tar.gz",
src = "image-bundle.tar",
)
[gzip(
name = "image-bundle-%s.tar.gz" % arch,
src = "image-bundle-%s.tar" % arch,
) for arch in ARCH]

load("//tools:hashes.bzl", "hashes")

hashes(
name = "image-bundle.tar.gz.hashes",
src = "image-bundle.tar.gz",
)
[hashes(
name = "image-bundle-%s.tar.gz.hashes" % arch,
src = "image-bundle-%s.tar.gz" % arch,
) for arch in ARCH]

[container_push(
name = "push-image-%s" % arch,
format = "Docker",
image = ":image-%s" % arch,
registry = "{STABLE_DOCKER_REGISTRY}",
repository = "{STABLE_DOCKER_IMAGE_PREFIX}kops-controller",
tag = "{STABLE_KOPS_CONTROLLER_TAG}-%s" % arch,
) for arch in ARCH]
69 changes: 37 additions & 32 deletions cmd/kube-apiserver-healthcheck/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ go_library(
],
)

go_test(
name = "go_default_test",
srcs = ["proxy_test.go"],
embed = [":go_default_library"],
)

go_binary(
name = "kube-apiserver-healthcheck",
embed = [":go_default_library"],
Expand All @@ -20,54 +26,53 @@ go_binary(
load(
"@io_bazel_rules_docker//container:container.bzl",
"container_image",
"container_push",
"container_bundle",
"container_push",
)

container_image(
name = "image",
ARCH = [
"amd64",
"arm64",
]

[container_image(
name = "image-%s" % arch,
architecture = arch,
base = "@distroless_base//image",
cmd = ["/usr/bin/kube-apiserver-healthcheck"],
cmd = ["/kube-apiserver-healthcheck"],
user = "10012",
directory = "/usr/bin/",
files = [
"//cmd/kube-apiserver-healthcheck",
],
stamp = True,
)

container_push(
name = "push-image",
format = "Docker",
image = ":image",
registry = "{STABLE_DOCKER_REGISTRY}",
repository = "{STABLE_DOCKER_IMAGE_PREFIX}kube-apiserver-healthcheck",
tag = "{STABLE_KUBE_APISERVER_HEALTHCHECK_TAG}",
)
) for arch in ARCH]

container_bundle(
name = "image-bundle",
[container_bundle(
name = "image-bundle-%s" % arch,
images = {
"{STABLE_DOCKER_IMAGE_PREFIX}kube-apiserver-healthcheck:{STABLE_KUBE_APISERVER_HEALTHCHECK_TAG}": "image",
"{STABLE_DOCKER_IMAGE_PREFIX}kube-apiserver-healthcheck:{STABLE_KUBE_APISERVER_HEALTHCHECK_TAG}": "image-%s" % arch,
},
)
) for arch in ARCH]

load("//tools:gzip.bzl", "gzip")

gzip(
name = "image-bundle.tar.gz",
src = "image-bundle.tar",
)
[gzip(
name = "image-bundle-%s.tar.gz" % arch,
src = "image-bundle-%s.tar" % arch,
) for arch in ARCH]

load("//tools:hashes.bzl", "hashes")

hashes(
name = "image-bundle.tar.gz.hashes",
src = "image-bundle.tar.gz",
)
[hashes(
name = "image-bundle-%s.tar.gz.hashes" % arch,
src = "image-bundle-%s.tar.gz" % arch,
) for arch in ARCH]

go_test(
name = "go_default_test",
srcs = ["proxy_test.go"],
embed = [":go_default_library"],
)
[container_push(
name = "push-image-%s" % arch,
format = "Docker",
image = ":image-%s" % arch,
registry = "{STABLE_DOCKER_REGISTRY}",
repository = "{STABLE_DOCKER_IMAGE_PREFIX}kube-apiserver-healthcheck",
tag = "{STABLE_KUBE_APISERVER_HEALTHCHECK_TAG}-%s" % arch,
) for arch in ARCH]
61 changes: 33 additions & 28 deletions dns-controller/cmd/dns-controller/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -39,48 +39,53 @@ go_binary(
load(
"@io_bazel_rules_docker//container:container.bzl",
"container_image",
"container_push",
"container_bundle",
"container_push",
)

container_image(
name = "image",
ARCH = [
"amd64",
"arm64",
]

[container_image(
name = "image-%s" % arch,
architecture = arch,
base = "@distroless_base//image",
cmd = ["/usr/bin/dns-controller"],
cmd = ["/dns-controller"],
user = "10001",
directory = "/usr/bin/",
files = [
"dns-controller",
"//dns-controller/cmd/dns-controller",
],
stamp = True,
)

container_push(
name = "push-image",
format = "Docker",
image = ":image",
registry = "{STABLE_DOCKER_REGISTRY}",
repository = "{STABLE_DOCKER_IMAGE_PREFIX}dns-controller",
tag = "{STABLE_DNS_CONTROLLER_TAG}",
)
) for arch in ARCH]

container_bundle(
name = "image-bundle",
[container_bundle(
name = "image-bundle-%s" % arch,
images = {
"{STABLE_DOCKER_IMAGE_PREFIX}dns-controller:{STABLE_DNS_CONTROLLER_TAG}": "image",
"{STABLE_DOCKER_IMAGE_PREFIX}dns-controller:{STABLE_DNS_CONTROLLER_TAG}": "image-%s" % arch,
},
)
) for arch in ARCH]

load("//tools:gzip.bzl", "gzip")

gzip(
name = "image-bundle.tar.gz",
src = "image-bundle.tar",
)
[gzip(
name = "image-bundle-%s.tar.gz" % arch,
src = "image-bundle-%s.tar" % arch,
) for arch in ARCH]

load("//tools:hashes.bzl", "hashes")

hashes(
name = "image-bundle.tar.gz.hashes",
src = "image-bundle.tar.gz",
)
[hashes(
name = "image-bundle-%s.tar.gz.hashes" % arch,
src = "image-bundle-%s.tar.gz" % arch,
) for arch in ARCH]

[container_push(
name = "push-image-%s" % arch,
format = "Docker",
image = ":image-%s" % arch,
registry = "{STABLE_DOCKER_REGISTRY}",
repository = "{STABLE_DOCKER_IMAGE_PREFIX}dns-controller",
tag = "{STABLE_DNS_CONTROLLER_TAG}-%s" % arch,
) for arch in ARCH]
50 changes: 0 additions & 50 deletions images/BUILD.bazel

This file was deleted.

10 changes: 5 additions & 5 deletions nodeup/pkg/model/protokube.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (t *ProtokubeBuilder) Build(c *fi.ModelBuilderContext) error {
return nil
}

if protokubeImage := t.NodeupConfig.ProtokubeImage; protokubeImage != nil {
if protokubeImage := t.NodeupConfig.ProtokubeImage[t.Architecture]; protokubeImage != nil {
c.AddTask(&nodetasks.LoadImageTask{
Name: "protokube",
Sources: protokubeImage.Sources,
Expand Down Expand Up @@ -166,8 +166,8 @@ func (t *ProtokubeBuilder) buildSystemdService() (*nodetasks.Service, error) {
// ProtokubeImageName returns the docker image for protokube
func (t *ProtokubeBuilder) ProtokubeImageName() string {
name := ""
if t.NodeupConfig.ProtokubeImage != nil && t.NodeupConfig.ProtokubeImage.Name != "" {
name = t.NodeupConfig.ProtokubeImage.Name
if t.NodeupConfig.ProtokubeImage[t.Architecture] != nil && t.NodeupConfig.ProtokubeImage[t.Architecture].Name != "" {
name = t.NodeupConfig.ProtokubeImage[t.Architecture].Name
}
if name == "" {
// use current default corresponding to this version of nodeup
Expand All @@ -179,8 +179,8 @@ func (t *ProtokubeBuilder) ProtokubeImageName() string {
// ProtokubeImagePullCommand returns the command to pull the image
func (t *ProtokubeBuilder) ProtokubeImagePullCommand() (string, error) {
var sources []string
if t.NodeupConfig.ProtokubeImage != nil {
sources = t.NodeupConfig.ProtokubeImage.Sources
if t.NodeupConfig.ProtokubeImage[t.Architecture] != nil {
sources = t.NodeupConfig.ProtokubeImage[t.Architecture].Sources
}
if len(sources) == 0 {
// Nothing to pull; return dummy value
Expand Down
3 changes: 2 additions & 1 deletion nodeup/pkg/model/protokube_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"k8s.io/kops/pkg/apis/nodeup"
"k8s.io/kops/upup/pkg/fi"
"k8s.io/kops/util/pkg/architectures"
)

func TestProtokubeBuilder_Docker(t *testing.T) {
Expand All @@ -43,7 +44,7 @@ func populateImage(ctx *NodeupModelContext) {
if ctx.NodeupConfig == nil {
ctx.NodeupConfig = &nodeup.Config{}
}
ctx.NodeupConfig.ProtokubeImage = &nodeup.Image{
ctx.NodeupConfig.ProtokubeImage[architectures.ArchitectureAmd64] = &nodeup.Image{
Name: "protokube image name",
}
}
2 changes: 1 addition & 1 deletion pkg/apis/nodeup/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type Config struct {
// ClusterName is the name of the cluster
ClusterName string `json:",omitempty"`
// ProtokubeImage is the docker image to load for protokube (bootstrapping)
ProtokubeImage *Image `json:"protokubeImage,omitempty"`
ProtokubeImage map[architectures.Architecture]*Image `json:"protokubeImage,omitempty"`
// Channels is a list of channels that we should apply
Channels []string `json:"channels,omitempty"`
// ApiserverAdditionalIPs are additional IP address to put in the apiserver server cert.
Expand Down
2 changes: 1 addition & 1 deletion pkg/model/components/kubeapiserver/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ spec:
initialDelaySeconds: 5
timeoutSeconds: 5
command:
- /usr/bin/kube-apiserver-healthcheck
- /kube-apiserver-healthcheck
args:
- --ca-cert=/secrets/ca.crt
- --client-cert=/secrets/client.crt
Expand Down
Loading

0 comments on commit 9d8decf

Please sign in to comment.