Skip to content

Commit

Permalink
operator: Move K8s init logic to function
Browse files Browse the repository at this point in the history
This commit is mostly a refactoring change to ease future commits. It
also removes a duplicated `Update()` call which is already done in
`Init()`.

Signed-off-by: Chris Tarazi <chris@isovalent.com>
  • Loading branch information
christarazi authored and aanm committed Sep 29, 2020
1 parent 325547f commit db9f562
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,21 @@ func initEnv() {
option.Config.EnableK8sLeasesFallbackDiscovery()
}

func initK8s(k8sInitDone chan struct{}) {
k8s.Configure(
option.Config.K8sAPIServer,
option.Config.K8sKubeConfigPath,
float32(option.Config.K8sClientQPSLimit),
option.Config.K8sClientBurst,
)

if err := k8s.Init(option.Config); err != nil {
log.WithError(err).Fatal("Unable to connect to Kubernetes apiserver")
}

close(k8sInitDone)
}

func doCleanup(exitCode int) {
isLeader.Store(false)
gops.Close()
Expand Down Expand Up @@ -176,29 +191,9 @@ func runOperator() {
operatorMetrics.Register()
}

k8s.Configure(
option.Config.K8sAPIServer,
option.Config.K8sKubeConfigPath,
float32(option.Config.K8sClientQPSLimit),
option.Config.K8sClientBurst,
)
if err := k8s.Init(option.Config); err != nil {
log.WithError(err).Fatal("Unable to connect to Kubernetes apiserver")
}
close(k8sInitDone)
initK8s(k8sInitDone)

// We try to update the Kubernetes version and capabilities. If this fails,
// we cannot move forward as we can misinterpret the available Capabilities.
// For example, in a case where we got an error when checking for Leases support
// we should not assume that support is not available and run the operator
// in non HA mode. As this can conflict with other operator instances running
// in the cluster, that figured the capabilities correctly and is running in HA
// mode.
if err := k8sversion.Update(k8s.Client(), option.Config); err != nil {
log.WithError(err).Fatal("Unable to update Kubernetes capabilities")
}
capabilities := k8sversion.Capabilities()

if !capabilities.MinimalVersionMet {
log.Fatalf("Minimal kubernetes version not met: %s < %s",
k8sversion.Version(), k8sversion.MinimalVersionConstraint)
Expand Down

0 comments on commit db9f562

Please sign in to comment.