Skip to content

Commit

Permalink
chore: remove loki to vali migration code
Browse files Browse the repository at this point in the history
  • Loading branch information
nickytd committed Jun 18, 2024
1 parent acf1b7e commit d61b094
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 67 deletions.
43 changes: 0 additions & 43 deletions pkg/controller/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ func (ctl *controller) newControllerClient(clientConf *config.Config) (Controlle
return c, nil
}

// TODO (nickytd) The checkTargetLoggingBackend parameter is only used to reckognize initial start of the cluster
// informer and propagate further down to getClientConfig if this is an add callback or update callback.
// Once vali to vali migration is done then we shall revert the original state and remove this parameter.
func (ctl *controller) createControllerClient(clusterName string, shoot *gardenercorev1beta1.Shoot) {
clientConf := ctl.getClientConfig(clusterName)
if clientConf == nil {
Expand Down Expand Up @@ -112,46 +109,6 @@ func (ctl *controller) updateControllerClientState(client ControllerClient, shoo
client.SetState(getShootState(shoot))
}

func (ctl *controller) recreateControllerClient(clusterName string, shoot *gardenercorev1beta1.Shoot) {
clientConf := ctl.getClientConfig(clusterName)
if clientConf == nil {
return
}

ctl.lock.Lock()
existing, ok := ctl.clients[clusterName]
ctl.lock.Unlock()

if ok && existing != nil && existing.GetEndPoint() == clientConf.ClientConfig.CredativValiConfig.URL.String() {
_ = level.Debug(ctl.logger).Log("msg", "try to change the endpoint, but they are the same", "cluster", clusterName, "endpoint", existing.GetEndPoint())
return
}

_ = level.Info(ctl.logger).Log("msg", "changing client endpoint", "cluster", clusterName, "oldEndpoint", existing.GetEndPoint(), "newEndpoint", clientConf.ClientConfig.CredativValiConfig.URL.String())

if ok && existing != nil {
existing.Stop()
}

newClient, err := ctl.newControllerClient(clientConf)
if err != nil {
metrics.Errors.WithLabelValues(metrics.ErrorFailedToMakeValiClient).Inc()
_ = level.Error(ctl.logger).Log("msg", fmt.Sprintf("failed to make new vali client for cluster %v", clusterName), "error", err.Error())
return
}

ctl.updateControllerClientState(newClient, shoot)

_ = level.Info(ctl.logger).Log("msg", "add client", "cluster", clusterName, "state", newClient.GetState())
ctl.lock.Lock()
defer ctl.lock.Unlock()

if ctl.isStopped() {
return
}
ctl.clients[clusterName] = newClient
}

// ClusterState is a type alias for string.
type clusterState string

Expand Down
25 changes: 1 addition & 24 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@
package controller

import (
"bufio"
"bytes"
"fmt"
"io/ioutil"
"net/http"
"strings"
"sync"
"time"

Expand All @@ -28,10 +24,7 @@ import (
)

const (
expectedActiveClusters = 128
loggingBackendConfigEndPoint = ".svc:3100/config"
lokiAPIPushEndPoint = ".svc:3100/loki/api/v1/push"
valiAPIPushEndPoint = ".svc:3100/vali/api/v1/push"
expectedActiveClusters = 128
)

// Controller represent a k8s controller watching for resources and
Expand All @@ -51,9 +44,6 @@ type controller struct {
logger log.Logger
}

// getter is a function definition which is turned into a repeatbale call
type getter func(client http.Client, url string) (*http.Response, error)

// NewController return Controller interface
func NewController(informer cache.SharedIndexInformer, conf *config.Config, defaultClient client.ValiClient,
logger log.Logger) (Controller, error) {
Expand Down Expand Up @@ -277,16 +267,3 @@ func (ctl *controller) isDeletedShoot(shoot *gardenercorev1beta1.Shoot) bool {
func (ctl *controller) isStopped() bool {
return ctl.clients == nil
}

// Returns a getter function turned into a repeatable call with a retry limit and a delay
func retry(g getter, retries int, delay time.Duration) getter {
return func(client http.Client, url string) (*http.Response, error) {
for r := 0; ; r++ {
response, err := g(client, url)
if err == nil || r >= retries {
return response, err
}
time.Sleep(delay)
}
}
}

0 comments on commit d61b094

Please sign in to comment.