8000 Use custom nop image instead of busybox by imjasonh · Pull Request #371 · knative/build · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Sep 5, 2019. It is now read-only.

Use custom nop image instead of busybox #371

Merged
merged 1 commit into from
Sep 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions cmd/nop/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
Copyright 2018 The Knative Authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

import "fmt"

func main() {
fmt.Println("Build successful")
}
10 changes: 10 additions & 0 deletions config/999-cache.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,13 @@ metadata:
namespace: knative-build
spec:
image: gcr.io/cloud-builders/gcs-fetcher
---
apiVersion: caching.internal.knative.dev/v1alpha1
kind: Image
metadata:
name: nop
namespace: knative-build
spec:
# This is the Go import path for the binary that is containerized
# and substituted here.
image: github.com/knative/build/cmd/nop
3 changes: 2 additions & 1 deletion config/controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ spec:
"-stderrthreshold", "INFO",
"-creds-image", "github.com/knative/build/cmd/creds-init",
"-git-image", "github.com/knative/build/cmd/git-init",
"-nop-image", "github.com/knative/build/cmd/nop",
]
volumeMounts:
- name: config-logging
mountPath: /etc/config-logging
volumes:
- name: config-logging
configMap:
name: config-logging
name: config-logging
26 changes: 11 additions & 15 deletions pkg/builder/cluster/convert/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"flag"
"fmt"
"path/filepath"
"reflect"
"strings"

corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -63,13 +62,6 @@ var (
Name: "home",
VolumeSource: emptyVolumeSource,
}}
// A benign placeholder for when a container is required, but none was specified.
nopContainer = corev1.Container{
Name: "nop",
Image: "busybox",
Command: []string{"/bin/echo"},
Args: []string{"Build successful"},
}
)

func validateVolumes(vs []corev1.Volume) error {
Expand Down Expand Up @@ -106,6 +98,9 @@ var (
// The container with Git that we use to implement the Git source step.
gitImage = flag.String("git-image", "override-with-git:latest",
"The container image containing our Git binary.")
// The container that just prints build successful.
nopImage = flag.String("nop-image", "override-with-nop:latest",
"The container image run at the end of the build to log build success")
gcsFetcherImage = flag.String("gcs-fetcher-image", "gcr.io/cloud-builders/gcs-fetcher:latest",
"The container image containing our GCS fetcher binary.")
)
Expand Down Expand Up @@ -366,9 +361,12 @@ func FromCRD(build *v1alpha1.Build, kubeclient kubernetes.Interface) (*corev1.Po
},
Spec: corev1.PodSpec{
// If the build fails, don't restart it.
RestartPolicy: corev1.RestartPolicyNever,
InitContainers: initContainers,
Containers: []corev1.Container{nopContainer},
RestartPolicy: corev1.RestartPolicyNever,
InitContainers: initContainers,
Containers: []corev1.Container{{
Name: "nop",
Image: *nopImage,
}},
ServiceAccountName: build.Spec.ServiceAccountName,
Volumes: volumes,
NodeSelector: build.Spec.NodeSelector,
Expand Down Expand Up @@ -445,10 +443,8 @@ func filterImplicitVolumes(vs []corev1.Volume) []corev1.Volume {
func ToCRD(pod *corev1.Pod) (*v1alpha1.Build, error) {
podSpec := pod.Spec.DeepCopy()

for _, c := range podSpec.Containers {
if !reflect.DeepEqual(c, nopContainer) {
return nil, fmt.Errorf("unrecognized container spec, got: %v", podSpec.Containers)
}
if len(podSpec.Containers) != 1 {
return nil, fmt.Errorf("unrecognized container spec, got: %v", podSpec.Containers)
}

subPath := ""
Expand Down
5 changes: 5 additions & 0 deletions pkg/builder/cluster/convert/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ import (

var ignorePrivateResourceFields = cmpopts.IgnoreUnexported(resource.Quantity{})

var nopContainer = corev1.Container{
Name: "nop",
Image: *nopImage,
}

func read2CRD(f string) (*v1alpha1.Build, error) {
var bs v1alpha1.Build
if err := buildtest.DataAs(f, &bs.Spec); err != nil {
Expand Down
0