Skip to content

Commit

Permalink
Handle metricscollector case worker container have no command (#914)
Browse files Browse the repository at this point in the history
* Handle metricscollector case worker container have no command

* Change method name
  • Loading branch information
hougangliu authored and k8s-ci-robot committed Nov 8, 2019
1 parent eb6ff94 commit 6410b03
Show file tree
Hide file tree
Showing 376 changed files with 182,941 additions and 98 deletions.
172 changes: 158 additions & 14 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 23 additions & 14 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ required = [
name = "github.com/golang/mock"
version = "1.1.1"

[[override]]
name = "github.com/google/go-containerregistry"
# HEAD as of 2019-03-20
revision = "8d4083db9aa0d2fae6588c1acdbe6a1f5db461e3"

[[constraint]]
name = "github.com/golang/protobuf"
version = "1.2.0"
Expand All @@ -48,28 +53,32 @@ required = [
version = "1.3.0"

[[constraint]]
name = "sigs.k8s.io/controller-runtime"
version = "0.1.9"

[[override]]
name = "k8s.io/api"
version = "kubernetes-1.12.3"
version = "kubernetes-1.12.9"

[[constraint]]
[[override]]
name = "k8s.io/apimachinery"
version = "kubernetes-1.12.3"

[[constraint]]
name = "k8s.io/client-go"
version = "kubernetes-1.12.3"
version = "kubernetes-1.12.9"

[[constraint]]
[[override]]
name = "k8s.io/code-generator"
version = "kubernetes-1.12.3"
version = "kubernetes-1.12.9"

[[constraint]]
name = "sigs.k8s.io/controller-runtime"
version = "0.1.9"
[[override]]
name = "k8s.io/client-go"
version = "kubernetes-1.12.9"

[[override]]
name = "k8s.io/apiextensions-apiserver"
version = "kubernetes-1.12.9"

[[override]]
name="k8s.io/apiextensions-apiserver"
version="kubernetes-1.12.3"
name = "k8s.io/kubernetes"
version = "v1.13.3"

[[override]]
name = "gopkg.in/fsnotify.v1"
Expand Down
1 change: 1 addition & 0 deletions cmd/katib-controller/v1alpha3/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ RUN if [ "$(uname -m)" = "ppc64le" ]; then \
# Copy the controller-manager into a thin image
FROM alpine:3.7
WORKDIR /app
RUN apk update && apk add ca-certificates
COPY --from=build-env /go/src/github.com/kubeflow/katib/cmd/katib-controller/katib-controller .
ENTRYPOINT ["./katib-controller"]
16 changes: 6 additions & 10 deletions pkg/webhook/v1alpha3/pod/inject_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (s *sidecarInjector) Mutate(pod *v1.Pod, namespace string) (*v1.Pod, error)
}
}
if needWrapWorkerContainer(trial.Spec.MetricsCollector) {
if err = wrapWorkerContainer(mutatedPod, kind, mountPath, pathKind, trial.Spec.MetricsCollector); err != nil {
if err = wrapWorkerContainer(mutatedPod, namespace, kind, mountPath, pathKind, trial.Spec.MetricsCollector); err != nil {
return nil, err
}
}
Expand Down Expand Up @@ -223,7 +223,7 @@ func needWrapWorkerContainer(mc common.MetricsCollectorSpec) bool {
}

func wrapWorkerContainer(
pod *v1.Pod, jobKind, metricsFile string,
pod *v1.Pod, namespace, jobKind, metricsFile string,
pathKind common.FileSystemKind,
mc common.MetricsCollectorSpec) error {
index := -1
Expand All @@ -238,22 +238,18 @@ func wrapWorkerContainer(
}
}
if index >= 0 {
// TODO(hougangliu): handle container.command is nil case
c := &pod.Spec.Containers[index]
command := []string{"sh", "-c"}
args := []string{}
if c.Command != nil {
args = append(args, c.Command...)
}
if c.Args != nil {
args = append(args, c.Args...)
args, err := getContainerCommand(pod, namespace, index)
if err != nil {
return err
}
if mc.Collector.Kind == common.StdOutCollector {
redirectStr := fmt.Sprintf("1>%s 2>&1", metricsFile)
args = append(args, redirectStr)
}
args = append(args, "&&", getMarkCompletedCommand(metricsFile, pathKind))
argsStr := strings.Join(args, " ")
c := &pod.Spec.Containers[index]
c.Command = command
c.Args = []string{argsStr}
}
Expand Down
Loading

0 comments on commit 6410b03

Please sign in to comment.