Skip to content
This repository is currently being migrated. It's locked while the migration is in progress.

Commit

Permalink
Use ondat/operator-toolkit (#140)
Browse files Browse the repository at this point in the history
Library changes:
* The package go.opentelemetry.io/otel/label has been replaced with
  go.opentelemetry.io/otel/attribute.
* The method WithLogger has been replaced with WithInstrumentation.
  • Loading branch information
walle authored Jun 15, 2022
1 parent f0ccc1a commit 61cd8b7
Show file tree
Hide file tree
Showing 459 changed files with 42,162 additions and 23,128 deletions.
40 changes: 20 additions & 20 deletions controllers/fencer/fencer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import (
"fmt"
"strconv"

actionv1 "github.com/darkowlzz/operator-toolkit/controller/stateless-action/v1"
"github.com/darkowlzz/operator-toolkit/controller/stateless-action/v1/action"
"github.com/go-logr/logr"
"github.com/hashicorp/go-multierror"
actionv1 "github.com/ondat/operator-toolkit/controller/stateless-action/v1"
"github.com/ondat/operator-toolkit/controller/stateless-action/v1/action"
"github.com/pkg/errors"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/label"
corev1 "k8s.io/api/core/v1"
storagev1 "k8s.io/api/storage/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -70,7 +70,7 @@ func NewController(k8s client.Client, cache *cache.Object, scheme *runtime.Schem
func (c Controller) GetObject(ctx context.Context, key client.ObjectKey) (interface{}, error) {
tr := otel.Tracer("fencer")
_, span := tr.Start(ctx, "get object")
span.SetAttributes(label.String("key", key.String()))
span.SetAttributes(attribute.String("key", key.String()))
defer span.End()

// Query the object details from the cache.
Expand All @@ -97,7 +97,7 @@ func (c Controller) RequireAction(ctx context.Context, o interface{}) (bool, err
span.RecordError(ErrNodeTypeAssertion)
return false, ErrNodeTypeAssertion
}
span.SetAttributes(label.String("node", node.GetName()))
span.SetAttributes(attribute.String("node", node.GetName()))

// Check if an associated k8s node exists. Action not required if k8s node
// doesn't exist.
Expand Down Expand Up @@ -272,7 +272,7 @@ func (am fenceActionManager) getTargetPods(ctx context.Context) (*corev1.PodList
func (am *fenceActionManager) fenceNode(ctx context.Context, obj client.Object) error {
tr := otel.Tracer("fencer")
ctx, span := tr.Start(ctx, "fence node")
span.SetAttributes(label.String("name", obj.GetName()))
span.SetAttributes(attribute.String("name", obj.GetName()))
defer span.End()

// Fetch volume attachments for node.
Expand Down Expand Up @@ -304,7 +304,7 @@ func (am *fenceActionManager) fenceNode(ctx context.Context, obj client.Object)
func (am *fenceActionManager) fencePod(ctx context.Context, pod *corev1.Pod, vaList *storagev1.VolumeAttachmentList) error {
tr := otel.Tracer("fencer")
ctx, span := tr.Start(ctx, "fence pod")
span.SetAttributes(label.String("name", pod.GetName()), label.String("namespace", pod.GetNamespace()))
span.SetAttributes(attribute.String("name", pod.GetName()), attribute.String("namespace", pod.GetNamespace()))
defer span.End()
log := am.log.WithValues("pod", pod.GetName(), "namespace", pod.GetNamespace())

Expand Down Expand Up @@ -368,7 +368,7 @@ func (am *fenceActionManager) fencePod(ctx context.Context, pod *corev1.Pod, vaL
// Instead, failover will take longer waiting for the VA to expire.
for _, pvc := range pvcs {
ctx, span := tr.Start(ctx, "delete volume attachment")
span.SetAttributes(label.String("pvc", pvc.GetName()))
span.SetAttributes(attribute.String("pvc", pvc.GetName()))
defer span.End()
log := log.WithValues("pvc", pvc.GetName())

Expand All @@ -378,7 +378,7 @@ func (am *fenceActionManager) fencePod(ctx context.Context, pod *corev1.Pod, vaL
log.Info("no volume attachment found for pvc")
continue
}
span.SetAttributes(label.String("va", va.GetName()), label.String("node", va.Spec.NodeName))
span.SetAttributes(attribute.String("va", va.GetName()), attribute.String("node", va.Spec.NodeName))
log = log.WithValues("va", va.GetName(), "node", va.Spec.NodeName)

// This should never happen as we're only processing StorageOS PVCs, but
Expand Down Expand Up @@ -410,19 +410,19 @@ func (am *fenceActionManager) podPVCs(ctx context.Context, pod *corev1.Pod) ([]*

tr := otel.Tracer("fencer")
ctx, span := tr.Start(ctx, "pod pvcs")
span.SetAttributes(label.String("name", pod.GetName()), label.String("namespace", pod.GetNamespace()))
span.SetAttributes(attribute.String("name", pod.GetName()), attribute.String("namespace", pod.GetNamespace()))
defer span.End()
log := am.log.WithValues("pod", pod.GetName(), "namespace", pod.GetNamespace())

for _, vol := range pod.Spec.Volumes {
ctx, span := tr.Start(ctx, "pod volume")
span.SetAttributes(label.String("volume", vol.Name))
span.SetAttributes(attribute.String("volume", vol.Name))
defer span.End()
if vol.PersistentVolumeClaim == nil || vol.PersistentVolumeClaim.ClaimName == "" {
span.SetStatus(codes.Ok, "no pvc for this volume type")
continue
}
span.SetAttributes(label.String("claim", vol.PersistentVolumeClaim.ClaimName))
span.SetAttributes(attribute.String("claim", vol.PersistentVolumeClaim.ClaimName))
key := client.ObjectKey{
Name: vol.PersistentVolumeClaim.ClaimName,
Namespace: pod.Namespace,
Expand All @@ -434,13 +434,13 @@ func (am *fenceActionManager) podPVCs(ctx context.Context, pod *corev1.Pod) ([]*
errors = multierror.Append(errors, err)
continue
}
span.SetAttributes(label.String("spec", pvc.Spec.String()))
span.SetAttributes(attribute.String("spec", pvc.Spec.String()))

// If the volume was dynamically provisioned, an annotation with the
// driver name will be set. This saves a PV lookup.
provisioner, ok := pvc.Annotations[provisioner.PVCProvisionerAnnotationKey]
if ok {
span.SetAttributes(label.String("provisioner", provisioner))
span.SetAttributes(attribute.String("provisioner", provisioner))
if provisioner == DriverName {
pvcs = append(pvcs, pvc)
}
Expand All @@ -460,7 +460,7 @@ func (am *fenceActionManager) podPVCs(ctx context.Context, pod *corev1.Pod) ([]*
continue
}
if pv.Spec.CSI != nil {
span.SetAttributes(label.String("pv provisioner", provisioner))
span.SetAttributes(attribute.String("pv provisioner", provisioner))
if pv.Spec.CSI.Driver == DriverName {
pvcs = append(pvcs, pvc)
}
Expand Down Expand Up @@ -497,11 +497,11 @@ func pvcVA(ctx context.Context, pvc *corev1.PersistentVolumeClaim, vaList *stora

for _, va := range vaList.Items {
if *va.Spec.Source.PersistentVolumeName == pvc.Spec.VolumeName {
span.SetAttributes(label.String("name", va.GetName()))
span.SetAttributes(label.String("attacher", va.Spec.Attacher))
span.SetAttributes(label.String("node", va.Spec.NodeName))
span.SetAttributes(label.String("pv", *va.Spec.Source.PersistentVolumeName))
span.SetAttributes(label.Bool("attached", va.Status.Attached))
span.SetAttributes(attribute.String("name", va.GetName()))
span.SetAttributes(attribute.String("attacher", va.Spec.Attacher))
span.SetAttributes(attribute.String("node", va.Spec.NodeName))
span.SetAttributes(attribute.String("pv", *va.Spec.Source.PersistentVolumeName))
span.SetAttributes(attribute.Bool("attached", va.Status.Attached))
return &va
}
}
Expand Down
12 changes: 6 additions & 6 deletions controllers/fencer/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import (
"context"
"time"

"github.com/darkowlzz/operator-toolkit/controller/external/builder"
"github.com/darkowlzz/operator-toolkit/controller/external/handler"
actionv1 "github.com/darkowlzz/operator-toolkit/controller/stateless-action/v1"
"github.com/go-logr/logr"
"github.com/ondat/operator-toolkit/controller/external/builder"
"github.com/ondat/operator-toolkit/controller/external/handler"
actionv1 "github.com/ondat/operator-toolkit/controller/stateless-action/v1"
"github.com/pkg/errors"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/label"
corev1 "k8s.io/api/core/v1"
storagev1 "k8s.io/api/storage/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -133,7 +133,7 @@ func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, wor
actionv1.WithScheme(mgr.GetScheme()),
actionv1.WithActionTimeout(timeout),
actionv1.WithActionRetryPeriod(retryInterval),
actionv1.WithLogger(r.log),
actionv1.WithInstrumentation(nil, nil, r.log),
)

return builder.ControllerManagedBy(mgr).
Expand Down Expand Up @@ -170,7 +170,7 @@ func (r *Reconciler) pollNodes(ctx context.Context, src chan event.GenericEvent)
span.End()
continue
}
span.SetAttributes(label.Int("nodes", len(nodes)))
span.SetAttributes(attribute.Int("nodes", len(nodes)))
for _, node := range nodes {
src <- event.GenericEvent{
Object: node,
Expand Down
9 changes: 4 additions & 5 deletions controllers/namespace-delete/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ package nsdelete

import (
"context"

syncv1 "github.com/darkowlzz/operator-toolkit/controller/sync/v1"
"github.com/go-logr/logr"
syncv1 "github.com/ondat/operator-toolkit/controller/sync/v1"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/label"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand Down Expand Up @@ -40,7 +39,7 @@ func (c Controller) Ensure(ctx context.Context, obj client.Object) error {
func (c Controller) Delete(ctx context.Context, obj client.Object) error {
tr := otel.Tracer("namespace-delete")
ctx, span := tr.Start(ctx, "namespace delete")
span.SetAttributes(label.String("name", obj.GetName()))
span.SetAttributes(attribute.String("name", obj.GetName()))
defer span.End()

ctx, cancel := context.WithTimeout(ctx, storageos.DefaultRequestTimeout)
Expand Down Expand Up @@ -73,7 +72,7 @@ func (c Controller) List(ctx context.Context) ([]types.NamespacedName, error) {
span.RecordError(err)
return nil, err
}
span.SetAttributes(label.Int("count", len(objects)))
span.SetAttributes(attribute.Int("count", len(objects)))
span.SetStatus(codes.Ok, "listed namespaces")
return storageos.ObjectKeys(objects), nil
}
6 changes: 3 additions & 3 deletions controllers/namespace-delete/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"fmt"
"time"

objectv1 "github.com/darkowlzz/operator-toolkit/controller/external-object-sync/v1"
syncv1 "github.com/darkowlzz/operator-toolkit/controller/sync/v1"
"github.com/go-logr/logr"
objectv1 "github.com/ondat/operator-toolkit/controller/external-object-sync/v1"
syncv1 "github.com/ondat/operator-toolkit/controller/sync/v1"
corev1 "k8s.io/api/core/v1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -65,7 +65,7 @@ func (r *Reconciler) SetupWithManager(mgr ctrl.Manager, workers int) error {
// Initialize the reconciler.
err = r.Reconciler.Init(mgr, c, &corev1.Namespace{}, &corev1.NamespaceList{},
syncv1.WithName("ns-delete"),
syncv1.WithLogger(r.log),
syncv1.WithInstrumentation(nil, nil, r.log),
)
if err != nil {
return fmt.Errorf("failed to create new reconciler: %w", err)
Expand Down
9 changes: 4 additions & 5 deletions controllers/node-delete/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ package nodedelete

import (
"context"

syncv1 "github.com/darkowlzz/operator-toolkit/controller/sync/v1"
"github.com/go-logr/logr"
syncv1 "github.com/ondat/operator-toolkit/controller/sync/v1"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/label"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand Down Expand Up @@ -39,7 +38,7 @@ func (c Controller) Ensure(ctx context.Context, obj client.Object) error {
func (c Controller) Delete(ctx context.Context, obj client.Object) error {
tr := otel.Tracer("node-delete")
ctx, span := tr.Start(ctx, "node delete")
span.SetAttributes(label.String("name", obj.GetName()))
span.SetAttributes(attribute.String("name", obj.GetName()))
defer span.End()

ctx, cancel := context.WithTimeout(ctx, storageos.DefaultRequestTimeout)
Expand Down Expand Up @@ -72,7 +71,7 @@ func (c Controller) List(ctx context.Context) ([]types.NamespacedName, error) {
span.RecordError(err)
return nil, err
}
span.SetAttributes(label.Int("count", len(nodes)))
span.SetAttributes(attribute.Int("count", len(nodes)))
span.SetStatus(codes.Ok, "listed nodes")

keys := []types.NamespacedName{}
Expand Down
6 changes: 3 additions & 3 deletions controllers/node-delete/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"fmt"
"time"

objectv1 "github.com/darkowlzz/operator-toolkit/controller/external-object-sync/v1"
syncv1 "github.com/darkowlzz/operator-toolkit/controller/sync/v1"
"github.com/go-logr/logr"
objectv1 "github.com/ondat/operator-toolkit/controller/external-object-sync/v1"
syncv1 "github.com/ondat/operator-toolkit/controller/sync/v1"
corev1 "k8s.io/api/core/v1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -63,7 +63,7 @@ func (r *Reconciler) SetupWithManager(mgr ctrl.Manager, workers int) error {
// Initialize the reconciler.
err = r.Reconciler.Init(mgr, c, &corev1.Node{}, &corev1.NodeList{},
syncv1.WithName("node-delete"),
syncv1.WithLogger(r.log),
syncv1.WithInstrumentation(nil, nil, r.log),
)
if err != nil {
return fmt.Errorf("failed to create new reconciler: %w", err)
Expand Down
8 changes: 4 additions & 4 deletions controllers/node-label/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"context"
"reflect"

msyncv1 "github.com/darkowlzz/operator-toolkit/controller/metadata-sync/v1"
"github.com/go-logr/logr"
msyncv1 "github.com/ondat/operator-toolkit/controller/metadata-sync/v1"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/label"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/storageos/api-manager/internal/pkg/storageos"
Expand Down Expand Up @@ -42,7 +42,7 @@ func NewController(api NodeLabeller, log logr.Logger) (*Controller, error) {
func (c Controller) Ensure(ctx context.Context, obj client.Object) error {
tr := otel.Tracer("node-label")
ctx, span := tr.Start(ctx, "node label ensure")
span.SetAttributes(label.String("name", obj.GetName()))
span.SetAttributes(attribute.String("name", obj.GetName()))
defer span.End()

ctx, cancel := context.WithTimeout(ctx, storageos.DefaultRequestTimeout)
Expand Down Expand Up @@ -85,7 +85,7 @@ func (c Controller) Diff(ctx context.Context, objs []client.Object) ([]client.Ob
apply = append(apply, obj)
}
}
span.SetAttributes(label.Int("stale nodes", len(apply)))
span.SetAttributes(attribute.Int("stale nodes", len(apply)))
span.SetStatus(codes.Ok, "compared nodes")
return apply, nil
}
Expand Down
6 changes: 3 additions & 3 deletions controllers/node-label/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"fmt"
"time"

msyncv1 "github.com/darkowlzz/operator-toolkit/controller/metadata-sync/v1"
syncv1 "github.com/darkowlzz/operator-toolkit/controller/sync/v1"
"github.com/go-logr/logr"
msyncv1 "github.com/ondat/operator-toolkit/controller/metadata-sync/v1"
syncv1 "github.com/ondat/operator-toolkit/controller/sync/v1"
corev1 "k8s.io/api/core/v1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -65,7 +65,7 @@ func (r *Reconciler) SetupWithManager(mgr ctrl.Manager, workers int) error {
// Initialize the reconciler.
err = r.Reconciler.Init(mgr, c, &corev1.Node{}, &corev1.NodeList{},
syncv1.WithName("node-label-sync"),
syncv1.WithLogger(r.log),
syncv1.WithInstrumentation(nil, nil, r.log),
)
if err != nil {
return fmt.Errorf("failed to create new reconciler: %w", err)
Expand Down
4 changes: 2 additions & 2 deletions controllers/pod_mutator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"context"
"time"

cclient "github.com/darkowlzz/operator-toolkit/client/composite"
"github.com/darkowlzz/operator-toolkit/webhook/cert"
cclient "github.com/ondat/operator-toolkit/client/composite"
"github.com/ondat/operator-toolkit/webhook/cert"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
admissionv1 "k8s.io/api/admissionregistration/v1"
Expand Down
10 changes: 5 additions & 5 deletions controllers/pvc-label/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import (
"fmt"
"reflect"

msyncv1 "github.com/darkowlzz/operator-toolkit/controller/metadata-sync/v1"
"github.com/darkowlzz/operator-toolkit/object"
"github.com/go-logr/logr"
msyncv1 "github.com/ondat/operator-toolkit/controller/metadata-sync/v1"
"github.com/ondat/operator-toolkit/object"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/label"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -49,7 +49,7 @@ func NewController(k8s client.Client, api VolumeLabeller, scheme *runtime.Scheme
func (c Controller) Ensure(ctx context.Context, obj client.Object) error {
tr := otel.Tracer("pvc-label")
ctx, span := tr.Start(ctx, "pvc label ensure")
span.SetAttributes(label.String("name", obj.GetName()))
span.SetAttributes(attribute.String("name", obj.GetName()))
defer span.End()

observeErr := func(err error) error {
Expand Down Expand Up @@ -147,7 +147,7 @@ func (c Controller) Diff(ctx context.Context, objs []client.Object) ([]client.Ob
apply = append(apply, obj)
}
}
span.SetAttributes(label.Int("stale volumes", len(apply)))
span.SetAttributes(attribute.Int("stale volumes", len(apply)))
span.SetStatus(codes.Ok, "compared volumes")
return apply, nil
}
Expand Down
Loading

0 comments on commit 61cd8b7

Please sign in to comment.