kubectl日志显示“ standard_init_linux.go:211:exec用户进程导致“没有此类文件或目录””

时间:2019-08-11 16:25:37

标签: docker events knative

我正在尝试创建用于容器化服务的containerSource。当我对图像使用docker run时,它将给出输出(“或代码中的错误”)。但是,当我应用yaml文件时,kubectl日志显示“ standard_init_linux.go:211:exec用户进程导致“没有此类文件或目录””。 docker run显示它能够找到exec文件。因此,我无法理解出了什么问题。有人请指导我。

我的Yaml文件:

apiVersion: sources.eventing.knative.dev/v1alpha1
kind: ContainerSource
metadata:
  labels:
    controller-tools.k8s.io: "1.0"
  name: cloudevents-source
spec:
  image: docker.io/username/pkt-event:latest
  args:
   - '--debug=true'
  sink:
    apiVersion: serving.knative.dev/v1alpha1
    kind: Service
    name: event-display

我对dockerimage的执行代码是:

package main

import (
        "context"
        "flag"
        "fmt"
        "log"
        "os"
        "time"
        "github.com/satori/go.uuid"
        "knative.dev/eventing-contrib/pkg/kncloudevents"
        "encoding/json"
//      "io/ioutil"
//      "knative.dev/eventing-contrib/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents"
        "github.com/cloudevents/sdk-go/pkg/cloudevents"
        "github.com/cloudevents/sdk-go/pkg/cloudevents/types"
        "github.com/kelseyhightower/envconfig"
)


var (
        eventSource string
        eventType   string
        sink        string
)
//var u, _ =  uuid.NewV4()

var debug = flag.Bool("debug", false, "Enable debug mode (print more information)")
var source = flag.String("source", uuid.NewV4().String(), "Set custom Source for the driver")

func init() {
        flag.StringVar(&eventSource, "eventSource", "", "the event-source (CloudEvents)")
        flag.StringVar(&eventType, "eventType", "dev.knative.eventing.samples.pkt", "the event-type (CloudEvents)")
        flag.StringVar(&sink, "sink", "", "the host url to send pkts to")
}

type envConfig struct {
        // Sink URL where to send heartbeat cloudevents
        Sink string `envconfig:"SINK"`
}

func main() {
        flag.Parse()

        var env envConfig
        if err := envconfig.Process("", &env); err != nil {
                log.Printf("[ERROR] Failed to process env var: %s", err)
                os.Exit(1)
        }

        if env.Sink != "" {
                sink = env.Sink
        }

        if eventSource == "" {
                eventSource = fmt.Sprintf("https://knative.dev/eventing-contrib/cmd/heartbeats/#local/demo")
                log.Printf("Source: %s", eventSource)
        }
        client, err := kncloudevents.NewDefaultClient(sink)
        if err != nil {
                log.Fatalf("failed to create client: %s", err.Error())
        }
        var period time.Duration
        period = time.Duration(1) * time.Second

        ticker := time.NewTicker(period)
        for {
                content := "Send data"
                data, err := json.Marshal(content)
                if err != nil {
                        fmt.Println(err)
                }
                event := cloudevents.Event{
                        Context: cloudevents.EventContextV02{
                                Type:   "packet.invoke",
                                Source: *types.ParseURLRef(eventSource),
                                /*Extensions: map[string]interface{}{
                                        "the":   42,
                                        "heart": "yes",
                                        "beats": true,
                                },*/
                        }.AsV02(),
                        Data: data,
                }
                if *debug{
                        log.Printf("Sending event %v", event)
                } else {
                        if _, err := client.Send(context.TODO(), event); err != nil {
                                log.Printf("failed to send cloudevent: %s", err.Error())
                        }
                }

                <-ticker.C
        }
}

Dockerfile是:

FROM golang:1.12 as builder
RUN go version

WORKDIR ${GOPATH}/src/Event-driver

COPY ./ ./

RUN  curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
##RUN dep ensure

RUN dep init
RUN dep ensure

RUN CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -v -o my-event my-event.go

RUN pwd && ls

FROM scratch
#FROM ubuntu:disco
COPY --from=builder /go/src/Event-driver/my-event /


ENTRYPOINT ["/my-event"]

1 个答案:

答案 0 :(得分:0)

发生此问题是因为您试图从bash运行二进制文件,但暂无bash。

我通常使用Alpina代替。要为Alpina进行构建,您需要相同的环境变量,因此可能只需要更改第二阶段的映像即可。