Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
31ac0c1
add cert-generator command
tenzen-y Sep 7, 2021
26f4cfe
go mod tidy
tenzen-y Sep 9, 2021
2c66840
fix gofmt lint check
tenzen-y Sep 9, 2021
3986c6a
fix unittest for katib-cert-generator
tenzen-y Sep 9, 2021
1075d26
remove unnecessary test code
tenzen-y Sep 10, 2021
928cf4b
fix comment
tenzen-y Sep 10, 2021
4e5f95d
review: fix kubeClient
tenzen-y Sep 10, 2021
0797cd5
review: stop to use k8s.io/utils
tenzen-y Sep 10, 2021
49680cf
review: delete containers[].securityContext
tenzen-y Sep 10, 2021
3d369b3
review: change directory name for cert-generator
tenzen-y Sep 10, 2021
3875a26
review: fix const
tenzen-y Sep 10, 2021
ee4de35
review: stop to use k8s.io/utils
tenzen-y Sep 10, 2021
b1d2220
review: delete containers[].securityContext
tenzen-y Sep 10, 2021
7a35691
review: change directory name for cert-generator
tenzen-y Sep 10, 2021
85c8410
review: fix const
tenzen-y Sep 10, 2021
78f53f2
Merge branch 'issue-1656-reimplement-katib-cert-generator' of https:/…
tenzen-y Sep 10, 2021
a3c391e
review: take webhook domain as consts
tenzen-y Sep 11, 2021
9b2b581
review: keep the name testDescription and err
tenzen-y Sep 11, 2021
eb9da24
review: do not try to patch webhook configuration in many times
tenzen-y Sep 11, 2021
5816bc7
review: fix some functions to generate cert
tenzen-y Sep 11, 2021
9c47bb9
review: add comments
tenzen-y Sep 11, 2021
ebd6ead
review: remove v1beta1 from admissionReviewVersions in ValidatingWebh…
tenzen-y Sep 11, 2021
a7a111d
fix comments
tenzen-y Sep 12, 2021
37a9156
review: remove the securityContext field
tenzen-y Sep 14, 2021
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
32 changes: 24 additions & 8 deletions cmd/cert-generator/v1beta1/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
FROM alpine:3.12.4
# Build the Katib Cert Generatoe.
FROM golang:alpine AS build-env

ARG KUBECTL_VERSION="v1.19.3"
WORKDIR /go/src/github.com/kubeflow/katib

RUN apk add --update openssl
RUN wget https://storage.googleapis.com/kubernetes-release/release/$KUBECTL_VERSION/bin/linux/amd64/kubectl \
&& chmod +x ./kubectl && mv ./kubectl /usr/local/bin/kubectl
# Download packages.
COPY go.mod .
COPY go.sum .
RUN go mod download -x

COPY ./hack/cert-generator.sh /app/cert-generator.sh
RUN chmod +x /app/cert-generator.sh
# Copy sources.
COPY cmd/ cmd/
COPY pkg/ pkg/

# Build the binary.
RUN if [ "$(uname -m)" = "ppc64le" ]; then \
CGO_ENABLED=0 GOOS=linux GOARCH=ppc64le go build -a -o katib-cert-generator ./cmd/cert-generator/v1beta1; \
elif [ "$(uname -m)" = "aarch64" ]; then \
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -a -o katib-cert-generator ./cmd/cert-generator/v1beta1; \
else \
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o katib-cert-generator ./cmd/cert-generator/v1beta1; \
fi

# Copy the cert-generator into a thin image.
FROM gcr.io/distroless/static:nonroot
WORKDIR /app
ENTRYPOINT ["sh", "./cert-generator.sh"]
COPY --from=build-env /go/src/github.com/kubeflow/katib/katib-cert-generator /app/
USER 65532:65532
ENTRYPOINT ["./katib-cert-generator"]
42 changes: 42 additions & 0 deletions cmd/cert-generator/v1beta1/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
Copyright 2021 The Kubeflow 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 (
"github.com/kubeflow/katib/pkg/cert-generator/v1beta1"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/klog"
"os"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/config"
)

func main() {
kubeClient, err := client.New(config.GetConfigOrDie(), client.Options{Scheme: scheme.Scheme})
if err != nil {
klog.Fatalf("Failed to create kube client.")
}

cmd, err := v1beta1.NewKatibCertGeneratorCmd(kubeClient)
if err != nil {
klog.Fatalf("Failed to generate cert: %v", err)
}

if err = cmd.Execute(); err != nil {
os.Exit(1)
}
}
7 changes: 3 additions & 4 deletions docs/developer-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,9 @@ to generate certificates for the webhooks.

Once Katib is deployed in the Kubernetes cluster, the `cert-generator` Job follows these steps:

- Generate a certificate using [`openssl`](https://www.openssl.org/).
- Generate the self-signed CA certificate and private key.

- Create a Kubernetes [Certificate Signing Request](https://kubernetes.io/docs/reference/access-authn-authz/certificate-signing-requests/)
to approve and sign the certificate.
- Generate public certificate and private key signed with the key generated in the previous step.

- Create a Kubernetes Secret with the signed certificate. Secret has
the `katib-webhook-cert` name and `cert-generator` Job's `ownerReference` to
Expand All @@ -115,7 +114,7 @@ Once Katib is deployed in the Kubernetes cluster, the `cert-generator` Job follo

- Patch the webhooks with the `CABundle`.

You can find the `cert-generator` source code [here](../hack/cert-generator.sh).
You can find the `cert-generator` source code [here](../cmd/cert-generator/v1beta1).

## Implement a new algorithm and use it in Katib

Expand Down
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/go-openapi/spec v0.19.3
github.com/go-sql-driver/mysql v1.5.0
github.com/golang/mock v1.6.0
github.com/golang/protobuf v1.4.3
github.com/golang/protobuf v1.5.2
github.com/google/go-containerregistry v0.4.1-0.20210128200529-19c2b639fab1
github.com/google/go-containerregistry/pkg/authn/k8schain v0.0.0-20210224013640-6928f6d356ab
github.com/grpc-ecosystem/go-grpc-middleware v1.2.0
Expand All @@ -20,10 +20,11 @@ require (
github.com/onsi/gomega v1.10.3
github.com/prometheus/client_golang v1.9.0
github.com/shirou/gopsutil v2.20.7+incompatible
github.com/spf13/viper v1.7.0
github.com/spf13/cobra v1.2.1
github.com/spf13/viper v1.8.1
github.com/tidwall/gjson v1.6.0
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4
google.golang.org/grpc v1.32.0
google.golang.org/grpc v1.38.0
gopkg.in/fsnotify/fsnotify.v1 v1.4.7 // indirect
k8s.io/api v0.20.4
k8s.io/apimachinery v0.20.4
Expand Down
Loading