Skip to content

Commit

Permalink
Use APIReader for Get/List resources on the autodetect functions
Browse files Browse the repository at this point in the history
Signed-off-by: Ruben Vargas <[email protected]>
  • Loading branch information
rubenvp8510 committed Dec 5, 2019
1 parent 6b2327e commit 578e6df
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ require (
go.opentelemetry.io/otel/exporter/trace/jaeger v0.1.2
golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f // indirect
golang.org/x/net v0.0.0-20191028085509-fe3aa8a45271
golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d // indirect
golang.org/x/tools v0.0.0-20191205002649-427c522ce2c7 // indirect
google.golang.org/grpc v1.24.0
k8s.io/api v0.0.0
k8s.io/apimachinery v0.0.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,8 @@ golang.org/x/tools v0.0.0-20191101200257-8dbcdeb83d3f/go.mod h1:b+2E5dAYhXwXZwtn
golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d h1:/iIZNFGxc/a7C3yWjGcnboV+Tkc7mxr+p6fDztwoxuM=
golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191205002649-427c522ce2c7 h1:R+waiss/kC/yzpcyEFoesbEJzgvWtLC4zRdYjBNKf1g=
golang.org/x/tools v0.0.0-20191205002649-427c522ce2c7/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 h1:9zdDQZ7Thm29KFXgAX/+yaf3eVbP7djjWp/dXAppNCc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gomodules.xyz/jsonpatch/v2 v2.0.1 h1:xyiBuvkD2g5n7cYzx6u2sxQvsAy4QJsZFCzGVdzOXZ0=
Expand Down
21 changes: 11 additions & 10 deletions pkg/autodetect/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ import (

// Background represents a procedure that runs in the background, periodically auto-detecting features
type Background struct {
cl client.Client
dcl discovery.DiscoveryInterface
ticker *time.Ticker
cl client.Client
clReader client.Reader
dcl discovery.DiscoveryInterface
ticker *time.Ticker

retryDetectKafka bool
retryDetectEs bool
Expand All @@ -37,16 +38,16 @@ func New(mgr manager.Manager) (*Background, error) {
return nil, err
}

return WithClients(mgr.GetClient(), dcl), nil
return WithClients(mgr.GetClient(), dcl, mgr.GetAPIReader()), nil
}

// WithClients builds a new Background with the provided clients
func WithClients(cl client.Client, dcl discovery.DiscoveryInterface) *Background {
func WithClients(cl client.Client, dcl discovery.DiscoveryInterface, clr client.Reader) *Background {
// whether we should keep adjusting depending on the environment
retryDetectEs := viper.GetString("es-provision") == v1.FlagProvisionElasticsearchAuto
retryDetectKafka := viper.GetString("kafka-provision") == v1.FlagProvisionKafkaAuto

return &Background{cl: cl, dcl: dcl, retryDetectKafka: retryDetectKafka, retryDetectEs: retryDetectEs}
return &Background{cl: cl, dcl: dcl, clReader: clr, retryDetectKafka: retryDetectKafka, retryDetectEs: retryDetectEs}
}

// Start initializes the auto-detection process that runs in the background
Expand Down Expand Up @@ -79,7 +80,7 @@ func (b *Background) Stop() {

func (b *Background) requireUpdates(deps *appsv1.DeploymentList) []*appsv1.Deployment {
instances := &v1.JaegerList{}
if err := b.cl.List(context.Background(), instances); err != nil {
if err := b.clReader.List(context.Background(), instances); err != nil {
log.WithError(err).Info("failed to retrieve the list of Jaeger instances")
return nil
}
Expand Down Expand Up @@ -122,7 +123,7 @@ func (b *Background) requireUpdates(deps *appsv1.DeploymentList) []*appsv1.Deplo

func (b *Background) detectDeploymentUpdates() error {
deps := &appsv1.DeploymentList{}
if err := b.cl.List(context.Background(), deps); err != nil {
if err := b.clReader.List(context.Background(), deps); err != nil {
return err
}
injectedDeps := b.requireUpdates(deps)
Expand Down Expand Up @@ -257,12 +258,12 @@ func (b *Background) cleanDeployments() {

instancesMap := make(map[string]*v1.Jaeger)

if err := b.cl.List(context.Background(), deployments, deployOpts...); err != nil {
if err := b.clReader.List(context.Background(), deployments, deployOpts...); err != nil {
log.WithError(err).Error("error cleaning orphaned deployment")
}

// get all jaeger instances
if err := b.cl.List(context.Background(), instances, jaegerOpts...); err != nil {
if err := b.clReader.List(context.Background(), instances, jaegerOpts...); err != nil {
log.WithError(err).Error("error cleaning orphaned deployment")
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/start/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func performUpgrades(ctx context.Context, mgr manager.Manager) {
defer span.End()

// upgrades all the instances managed by this operator
if err := upgrade.ManagedInstances(ctx, mgr.GetClient()); err != nil {
if err := upgrade.ManagedInstances(ctx, mgr.GetClient(), mgr.GetAPIReader()); err != nil {
log.WithError(err).Warn("failed to upgrade managed instances")
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

// ManagedInstances finds all the Jaeger instances for the current operator and upgrades them, if necessary
func ManagedInstances(ctx context.Context, c client.Client) error {
func ManagedInstances(ctx context.Context, c client.Client, reader client.Reader) error {
tracer := global.TraceProvider().GetTracer(v1.ReconciliationTracer)
ctx, span := tracer.Start(ctx, "ManagedInstances")
defer span.End()
Expand All @@ -24,7 +24,7 @@ func ManagedInstances(ctx context.Context, c client.Client) error {
opts := client.MatchingLabels(map[string]string{
v1.LabelOperatedBy: identity,
})
if err := c.List(ctx, list, opts); err != nil {
if err := reader.List(ctx, list, opts); err != nil {
return tracing.HandleError(err, span)
}

Expand Down

0 comments on commit 578e6df

Please sign in to comment.