Skip to content

Commit

Permalink
Update generated client code, migrate on interface changes
Browse files Browse the repository at this point in the history
  • Loading branch information
eMGabriel committed Mar 15, 2020
1 parent c20623d commit 9d3862c
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 26 deletions.
22 changes: 17 additions & 5 deletions cmd/svcwatcher/svcwatcher.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package main

import (
"context"
"flag"
"k8s.io/client-go/transport"
"log"
"time"
"os"
Expand Down Expand Up @@ -38,8 +40,17 @@ func main() {
cfg, err := clientcmd.BuildConfigFromFlags("", kubeconfig)
if err != nil {
glog.Fatalf("Error building kubeconfig: %s", err.Error())
return
}

// use a Go context so we can tell the leaderelection code when we
// want to step down
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

// use a client that will stop allowing new requests once the context ends
cfg.Wrap(transport.ContextCanceller(ctx, fmt.Errorf("the leader is shutting down")))

kubeClient, err := kubernetes.NewForConfig(cfg)
if err != nil {
glog.Fatalf("Error building kubernetes clientset: %s", err.Error())
Expand All @@ -59,11 +70,11 @@ func main() {
kubeInformerFactory.Core().V1().Endpoints(),
danmInformerFactory.Danm().V1().DanmEps())

run := func(stopCh <-chan struct{}) {
go kubeInformerFactory.Start(stopCh)
go danmInformerFactory.Start(stopCh)
run := func(ctx context.Context) {
go kubeInformerFactory.Start(ctx.Done())
go danmInformerFactory.Start(ctx.Done())

if err = controller.Run(10, stopCh); err != nil {
if err = controller.Run(10, ctx.Done()); err != nil {
glog.Fatalf("Error running controller: %s", err.Error())
}
}
Expand All @@ -72,6 +83,7 @@ func main() {
"kube-system",
"danm-svc-controller",
kubeClient.CoreV1(),
kubeClient.CoordinationV1(),
resourcelock.ResourceLockConfig{
Identity: GetHostname(),
EventRecorder: createRecorder(kubeClient, "danm-svc-controller"),
Expand All @@ -80,7 +92,7 @@ func main() {
glog.Fatalf("Error creating lock: %v", err)
}

leaderelection.RunOrDie(leaderelection.LeaderElectionConfig{
leaderelection.RunOrDie(ctx, leaderelection.LeaderElectionConfig{
Lock: rl,
LeaseDuration: 10 * time.Second,
RenewDeadline: 5 * time.Second,
Expand Down
1 change: 1 addition & 0 deletions crd/apis/danm/v1/doc.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:generate bash $PWD/vendor/k8s.io/code-generator/generate-groups.sh all github.com/nokia/danm/crd/client github.com/nokia/danm/crd/apis danm:v1 --go-header-file $PWD/hack/boilreplate.go.txt
// +k8s:deepcopy-gen=package

// Package v1 is the v1 version of the API.
Expand Down
10 changes: 5 additions & 5 deletions crd/apis/danm/v1/zz_generated.deepcopy.go

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

15 changes: 7 additions & 8 deletions crd/client/clientset/versioned/clientset.go

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

12 changes: 6 additions & 6 deletions crd/client/clientset/versioned/fake/clientset_generated.go

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

3 changes: 1 addition & 2 deletions crd/client/clientset/versioned/typed/danm/v1/danm_client.go

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

37 changes: 37 additions & 0 deletions hack/update-codegen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash

# Copyright 2020 The Kubernetes 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.

set -o errexit
set -o nounset
set -o pipefail

SCRIPT_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
CODEGEN_PKG=${CODEGEN_PKG:-$(cd "${SCRIPT_ROOT}"; ls -d -1 ./vendor/k8s.io/code-generator 2>/dev/null || echo ../code-generator)}

# Take a copy of code-generator boilerplate that will be used as licence header template for our generated client code
find "${GOPATH}" -path '*code-generator@*boilerplate.go.txt' -exec cp -f {} "${SCRIPT_ROOT}/hack/" \;

# generate the code with:
# --output-base because this script should also be able to run inside the vendor dir of
# k8s.io/kubernetes. The output-base is needed for the generators to output into the vendor dir
# instead of the $GOPATH directly. For normal projects this can be dropped.
bash "${CODEGEN_PKG}"/generate-groups.sh "deepcopy,client,informer,lister" \
github.com/nokia/danm/crd/client github.com/nokia/danm/crd/apis \
danm:v1 \
--go-header-file "${SCRIPT_ROOT}"/hack/boilerplate.go.txt

# To use your own boilerplate text append:
# --go-header-file "${SCRIPT_ROOT}"/hack/custom-boilerplate.go.txt

0 comments on commit 9d3862c

Please sign in to comment.