Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace dynamic client with controller-runtime client #4153

Merged
merged 5 commits into from
Nov 4, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions cmd/contour/certgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,12 @@ func doCertgen(config *certgenConfig, log logrus.FieldLogger) {
log.WithError(err).Fatal("failed to generate certificates")
}

clients, err := k8s.NewClients(config.KubeConfig, config.InCluster)
coreClient, err := k8s.NewCoreClient(config.KubeConfig, config.InCluster)
if err != nil {
log.WithError(err).Fatalf("failed to create Kubernetes client")
}

if oerr := OutputCerts(config, clients.ClientSet(), generatedCerts); oerr != nil {
if oerr := OutputCerts(config, coreClient, generatedCerts); oerr != nil {
log.WithError(oerr).Fatalf("failed output certificates")
}

Expand Down
2 changes: 0 additions & 2 deletions cmd/contour/ingressstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ type loadBalancerStatusWriter struct {
lbStatus chan v1.LoadBalancerStatus
statusUpdater k8s.StatusUpdater
ingressClassName string
Converter k8s.Converter
}

func (isw *loadBalancerStatusWriter) Start(stop <-chan struct{}) error {
Expand All @@ -78,7 +77,6 @@ func (isw *loadBalancerStatusWriter) Start(stop <-chan struct{}) error {
}(),
IngressClassName: isw.ingressClassName,
StatusUpdater: isw.statusUpdater,
Converter: isw.Converter,
}

// Create informers for the types that need load balancer
Expand Down
16 changes: 8 additions & 8 deletions cmd/contour/leadership.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import (
contour_api_v1alpha1 "github.com/projectcontour/contour/apis/projectcontour/v1alpha1"

"github.com/google/uuid"
"github.com/projectcontour/contour/internal/k8s"
"github.com/projectcontour/contour/internal/workgroup"
"github.com/sirupsen/logrus"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/leaderelection"
"k8s.io/client-go/tools/leaderelection/resourcelock"
)
Expand All @@ -43,9 +43,9 @@ func setupLeadershipElection(
g *workgroup.Group,
log logrus.FieldLogger,
conf contour_api_v1alpha1.LeaderElectionConfig,
clients *k8s.Clients, updateNow func(),
client *kubernetes.Clientset, updateNow func(),
) chan struct{} {
le, leader, deposed := newLeaderElector(log, conf, clients)
le, leader, deposed := newLeaderElector(log, conf, client)

g.AddContext(func(electionCtx context.Context) error {
log.WithFields(logrus.Fields{
Expand Down Expand Up @@ -88,7 +88,7 @@ func setupLeadershipElection(
func newLeaderElector(
log logrus.FieldLogger,
conf contour_api_v1alpha1.LeaderElectionConfig,
clients *k8s.Clients,
client *kubernetes.Clientset,
) (*leaderelection.LeaderElector, chan struct{}, chan struct{}) {
log = log.WithField("context", "leaderelection")
// leaderOK will block gRPC startup until it's closed.
Expand All @@ -97,7 +97,7 @@ func newLeaderElector(
// we are deposed as leader so that we can clean up.
deposed := make(chan struct{})

rl := newResourceLock(log, conf, clients)
rl := newResourceLock(log, conf, client)

leaseDuration, err := time.ParseDuration(conf.LeaseDuration)
if err != nil {
Expand Down Expand Up @@ -141,7 +141,7 @@ func newLeaderElector(

// newResourceLock creates a new resourcelock.Interface based on the Pod's name,
// or a uuid if the name cannot be determined.
func newResourceLock(log logrus.FieldLogger, conf contour_api_v1alpha1.LeaderElectionConfig, clients *k8s.Clients) resourcelock.Interface {
func newResourceLock(log logrus.FieldLogger, conf contour_api_v1alpha1.LeaderElectionConfig, client *kubernetes.Clientset) resourcelock.Interface {
resourceLockID, found := os.LookupEnv("POD_NAME")
if !found {
resourceLockID = uuid.New().String()
Expand All @@ -155,8 +155,8 @@ func newResourceLock(log logrus.FieldLogger, conf contour_api_v1alpha1.LeaderEle
resourcelock.ConfigMapsResourceLock,
conf.Configmap.Namespace,
conf.Configmap.Name,
clients.ClientSet().CoreV1(),
clients.ClientSet().CoordinationV1(),
client.CoreV1(),
client.CoordinationV1(),
resourcelock.ResourceLockConfig{
Identity: resourceLockID,
},
Expand Down
Loading