Skip to content

Commit

Permalink
Error when trying to build with windows builder
Browse files Browse the repository at this point in the history
- also clean up unused code

Signed-off-by: Tom Kennedy <[email protected]>
  • Loading branch information
tomkennedy513 committed Feb 28, 2025
1 parent cdeab05 commit 7b67daf
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 88 deletions.
45 changes: 0 additions & 45 deletions cmd/build-init/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@ package main
import (
"context"
"flag"
"io"
"log"
"net"
"os"
"path"
"path/filepath"
"strconv"
"strings"
"time"

"github.com/google/go-containerregistry/pkg/authn"
"github.com/google/go-containerregistry/pkg/authn/k8schain"
Expand Down Expand Up @@ -249,48 +246,6 @@ func logLoadingSecrets(logger *log.Logger, secretsSlices ...[]string) {
}
}

func waitForDns(hostname string) {
timeoutChan := time.After(10 * time.Second)
tickerChan := time.NewTicker(time.Second)
defer tickerChan.Stop()

for {
select {
case <-timeoutChan:
return
case <-tickerChan.C:
if _, err := net.LookupIP(hostname); err == nil {
return
}
}
}
}

func copyFile(src, dest string) error {
srcFile, err := os.Open(src)
if err != nil {
return err
}
defer srcFile.Close()

destFile, err := os.Create(dest)
if err != nil {
return err
}
defer destFile.Close()

if _, err = io.Copy(destFile, srcFile); err != nil {
return err
}

srcInfo, err := os.Stat(src)
if err != nil {
return err
}

return os.Chmod(dest, srcInfo.Mode())
}

func getenvInt(key string, defaultValue int) int {
value := os.Getenv(key)
atoi, err := strconv.Atoi(value)
Expand Down
36 changes: 2 additions & 34 deletions pkg/apis/build/v1alpha2/build_pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,12 @@ type BuildContext struct {
SSHTrustUnknownHost bool
}

func (c BuildContext) os() string {
return c.BuildPodBuilderConfig.OS
}

type BuildPodBuilderConfig struct {
StackID string
RunImage string
Uid int64
Gid int64
PlatformAPIs []string
OS string
}

var (
Expand Down Expand Up @@ -156,11 +151,6 @@ var (
MountPath: "/var/report",
ReadOnly: false,
}
networkWaitLauncherMount = corev1.VolumeMount{
Name: networkWaitLauncherVolumeName,
MountPath: "/networkWait",
ReadOnly: false,
}
homeEnv = corev1.EnvVar{
Name: "HOME",
Value: "/builder/home",
Expand All @@ -181,7 +171,6 @@ var (
)

type stepModifier func(corev1.Container) corev1.Container
type podModifier func(*corev1.Pod) *corev1.Pod

func (b *Build) BuildPod(images BuildPodImages, buildContext BuildContext) (*corev1.Pod, error) {
platformAPI, err := buildContext.highestSupportedPlatformAPI(b)
Expand Down Expand Up @@ -541,7 +530,7 @@ func (b *Build) BuildPod(images BuildPodImages, buildContext BuildContext) (*cor
)
}),
ServiceAccountName: b.Spec.ServiceAccountName,
NodeSelector: b.nodeSelector(buildContext.os()),
NodeSelector: map[string]string{k8sOSLabel: "linux"},
Tolerations: b.Spec.Tolerations,
Affinity: b.Spec.Affinity,
RuntimeClassName: b.Spec.RuntimeClassName,
Expand Down Expand Up @@ -703,18 +692,6 @@ func (b *Build) useStandardContainers(buildWaiterImage string, pod *corev1.Pod)
return pod
}

func userprofileHomeEnv() stepModifier {
return func(container corev1.Container) corev1.Container {
for i, env := range container.Env {
if env.Name == "HOME" {
container.Env[i].Name = "USERPROFILE"
}
}

return container
}
}

func (b *Build) notarySecretVolume() corev1.Volume {
config := b.NotaryV1Config()
if config == nil {
Expand Down Expand Up @@ -784,7 +761,7 @@ func (b *Build) rebasePod(buildContext BuildContext, images BuildPodImages) (*co
},
Spec: corev1.PodSpec{
ServiceAccountName: b.Spec.ServiceAccountName,
NodeSelector: b.nodeSelector("linux"),
NodeSelector: map[string]string{k8sOSLabel: "linux"},
Tolerations: b.Spec.Tolerations,
Affinity: b.Spec.Affinity,
RuntimeClassName: b.Spec.RuntimeClassName,
Expand Down Expand Up @@ -1050,15 +1027,6 @@ func (bc BuildContext) highestSupportedPlatformAPI(b *Build) (*semver.Version, e
return nil, errors.Errorf("unsupported builder platform API versions: %s", strings.Join(bc.BuildPodBuilderConfig.PlatformAPIs, ","))
}

func (b Build) nodeSelector(os string) map[string]string {
if b.Spec.NodeSelector == nil {
b.Spec.NodeSelector = map[string]string{}
}

b.Spec.NodeSelector[k8sOSLabel] = os
return b.Spec.NodeSelector
}

func setupBindingVolumesAndMounts(bindings []ServiceBinding) ([]corev1.Volume, []corev1.VolumeMount, error) {
volumes := make([]corev1.Volume, 0, len(bindings))
volumeMounts := make([]corev1.VolumeMount, 0, len(bindings))
Expand Down
4 changes: 0 additions & 4 deletions pkg/apis/build/v1alpha2/build_pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ func testBuildPod(t *testing.T, when spec.G, it spec.S) {
Uid: 2000,
Gid: 3000,
PlatformAPIs: []string{"0.7", "0.8", "0.9"},
OS: "linux",
},
Secrets: secrets,
Bindings: serviceBindings,
Expand Down Expand Up @@ -392,23 +391,20 @@ func testBuildPod(t *testing.T, when spec.G, it spec.S) {
Uid: 2000,
Gid: 3000,
PlatformAPIs: []string{"0.7", "0.8", "0.9"},
OS: "linux",
}.Uid, *pod.Spec.SecurityContext.RunAsUser)
assert.Equal(t, buildapi.BuildPodBuilderConfig{
StackID: "com.builder.stack.io",
RunImage: "builderregistry.io/run",
Uid: 2000,
Gid: 3000,
PlatformAPIs: []string{"0.7", "0.8", "0.9"},
OS: "linux",
}.Gid, *pod.Spec.SecurityContext.RunAsGroup)
assert.Equal(t, buildapi.BuildPodBuilderConfig{
StackID: "com.builder.stack.io",
RunImage: "builderregistry.io/run",
Uid: 2000,
Gid: 3000,
PlatformAPIs: []string{"0.7", "0.8", "0.9"},
OS: "linux",
}.Gid, *pod.Spec.SecurityContext.FSGroup)
})

Expand Down
5 changes: 4 additions & 1 deletion pkg/buildpod/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,16 @@ func (g *Generator) fetchBuilderConfig(ctx context.Context, build BuildPodable)
return buildapi.BuildPodBuilderConfig{}, err
}

if config.OS == "windows" {
return buildapi.BuildPodBuilderConfig{}, errors.New("windows builds are not supported")
}

return buildapi.BuildPodBuilderConfig{
StackID: stackId,
RunImage: metadata.Stack.RunImage.Image,
PlatformAPIs: append(metadata.Lifecycle.APIs.Platform.Deprecated, metadata.Lifecycle.APIs.Platform.Supported...),
Uid: uid,
Gid: gid,
OS: config.OS,
}, nil
}

Expand Down
25 changes: 21 additions & 4 deletions pkg/buildpod/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ func TestGenerator(t *testing.T) {
func testGenerator(t *testing.T, when spec.G, it spec.S) {
when("Generate", func() {
const (
serviceAccountName = "serviceAccountName"
namespace = "some-namespace"
linuxBuilderImage = "builder/linux"
serviceAccountName = "serviceAccountName"
namespace = "some-namespace"
linuxBuilderImage = "builder/linux"
windowsBuilderImage = "builder/windows"
)

var (
Expand Down Expand Up @@ -192,6 +193,8 @@ func testGenerator(t *testing.T, when spec.G, it spec.S) {
keychainFactory.AddKeychainForSecretRef(t, secretRef, keychain)

imageFetcher.AddImage(linuxBuilderImage, createImage(t, "linux"), keychain)
imageFetcher.AddImage(windowsBuilderImage, createImage(t, "windows"), keychain)

})

it("invokes the BuildPod with the builder and env config", func() {
Expand Down Expand Up @@ -221,7 +224,6 @@ func testGenerator(t *testing.T, when spec.G, it spec.S) {
Uid: 1234,
Gid: 5678,
PlatformAPIs: []string{"0.4", "0.5", "0.6"},
OS: "linux",
},
Bindings: []buildapi.ServiceBinding{},
ImagePullSecrets: []corev1.LocalObjectReference{
Expand Down Expand Up @@ -545,6 +547,21 @@ func testGenerator(t *testing.T, when spec.G, it spec.S) {
require.Len(t, build.buildPodCalls, 1)
assert.True(t, build.buildPodCalls[0].BuildContext.InjectedSidecarSupport)
})

it("errors when the builder is windowa", func() {

var build = &testBuildPodable{
serviceAccount: serviceAccountName,
namespace: namespace,
buildBuilderSpec: corev1alpha1.BuildBuilderSpec{
Image: windowsBuilderImage,
ImagePullSecrets: builderPullSecrets,
},
}

_, err := generator.Generate(context.TODO(), build)
require.EqualError(t, err, "windows builds are not supported")
})
})
}

Expand Down

0 comments on commit 7b67daf

Please sign in to comment.