From 91989d29e081e3700aa45a73477752afb79a8e95 Mon Sep 17 00:00:00 2001 From: outscale-vbr Date: Tue, 11 Oct 2022 18:25:42 +0000 Subject: [PATCH 1/2] Enable to have opentracing --- cloud/opentracing/metrics.go | 38 +++++ cloud/opentracing/opentelemetry.go | 47 +++++++ cloud/opentracing/traces.go | 74 ++++++++++ cloud/services/security/securitygroup.go | 2 +- controllers/osccluster_controller.go | 87 +++++++++++- controllers/oscmachine_controller.go | 67 ++++++++- go.mod | 38 +++-- go.sum | 68 +++++++-- main.go | 14 +- util/tele/composite_logger.go | 80 +++++++++++ util/tele/corr_id.go | 78 ++++++++++ util/tele/span_logger.go | 172 +++++++++++++++++++++++ util/tele/tele.go | 38 +++++ util/tracing/tracing.go | 53 +++++++ 14 files changed, 831 insertions(+), 25 deletions(-) create mode 100644 cloud/opentracing/metrics.go create mode 100644 cloud/opentracing/opentelemetry.go create mode 100644 cloud/opentracing/traces.go create mode 100644 util/tele/composite_logger.go create mode 100644 util/tele/corr_id.go create mode 100644 util/tele/span_logger.go create mode 100644 util/tele/tele.go create mode 100644 util/tracing/tracing.go diff --git a/cloud/opentracing/metrics.go b/cloud/opentracing/metrics.go new file mode 100644 index 000000000..aef1f8a95 --- /dev/null +++ b/cloud/opentracing/metrics.go @@ -0,0 +1,38 @@ +package opentracing + +import ( + "fmt" + crprometheus "github.com/prometheus/client_golang/prometheus" + "go.opentelemetry.io/otel/exporters/prometheus" + "go.opentelemetry.io/otel/metric/global" + "go.opentelemetry.io/otel/sdk/metric/aggregator/histogram" + controller "go.opentelemetry.io/otel/sdk/metric/controller/basic" + "go.opentelemetry.io/otel/sdk/metric/export/aggregation" + processor "go.opentelemetry.io/otel/sdk/metric/processor/basic" + selector "go.opentelemetry.io/otel/sdk/metric/selector/simple" + "sigs.k8s.io/controller-runtime/pkg/metrics" +) + +// RegisterMetrics enables prometheus metrics for OpenTelemetry. +func RegisterMetrics() error { + fmt.Printf("Register metrics opentracing \n") + config := prometheus.Config{ + Registry: metrics.Registry.(*crprometheus.Registry), // use the controller runtime metrics registry / gatherer + } + c := controller.New( + processor.NewFactory( + selector.NewWithHistogramDistribution( + histogram.WithExplicitBoundaries(config.DefaultHistogramBoundaries), + ), + aggregation.CumulativeTemporalitySelector(), + processor.WithMemory(true), + ), + ) + exporter, err := prometheus.New(config, c) + if err != nil { + return err + } + global.SetMeterProvider(exporter.MeterProvider()) + + return nil +} diff --git a/cloud/opentracing/opentelemetry.go b/cloud/opentracing/opentelemetry.go new file mode 100644 index 000000000..ab19060ec --- /dev/null +++ b/cloud/opentracing/opentelemetry.go @@ -0,0 +1,47 @@ +package opentracing + +import ( + "context" + "fmt" + "github.com/Azure/go-autorest/tracing" + "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp" + "go.opentelemetry.io/otel/trace" + "net/http" +) + +type ( + // OpenTelemetryAutorestTracer implements the tracing interface for AutoRest. + OpenTelemetryAutorestTracer struct { + tracer trace.Tracer + } +) + +var _ tracing.Tracer = (*OpenTelemetryAutorestTracer)(nil) + +// NewOpenTelemetryAutorestTracer creates a new Autorest tracing adapter for OpenTelemetry. +func NewOpenTelemetryAutorestTracer(tracer trace.Tracer) *OpenTelemetryAutorestTracer { + return &OpenTelemetryAutorestTracer{ + tracer: tracer, + } +} + +// NewTransport creates a new http.RoundTripper which will augment the base http.RoundTripper with OpenTelemetry +// tracing and metrics. +func (ot *OpenTelemetryAutorestTracer) NewTransport(base *http.Transport) http.RoundTripper { + return otelhttp.NewTransport(base) +} + +// StartSpan creates a new span of a given name and adds it to the given context.Context. +func (ot *OpenTelemetryAutorestTracer) StartSpan(ctx context.Context, name string) context.Context { + fmt.Printf("Start Span opentracing") + ctx, _ = ot.tracer.Start(ctx, name) + return ctx +} + +// EndSpan ends the current context span. It ignores the httpsStatusCode and error since they are recorded by +// the otelhttp.Transport. +func (ot *OpenTelemetryAutorestTracer) EndSpan(ctx context.Context, httpStatusCode int, err error) { + fmt.Printf("End Span opentracing") + span := trace.SpanFromContext(ctx) + span.End() +} diff --git a/cloud/opentracing/traces.go b/cloud/opentracing/traces.go new file mode 100644 index 000000000..31e737b52 --- /dev/null +++ b/cloud/opentracing/traces.go @@ -0,0 +1,74 @@ +package opentracing + +import ( + "context" + "fmt" + "github.com/go-logr/logr" + "github.com/outscale-dev/cluster-api-provider-outscale.git/util/tele" + "github.com/outscale-dev/cluster-api-provider-outscale.git/util/tracing" + "github.com/pkg/errors" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc" + "go.opentelemetry.io/otel/propagation" + "go.opentelemetry.io/otel/sdk/resource" + sdktrace "go.opentelemetry.io/otel/sdk/trace" + semconv "go.opentelemetry.io/otel/semconv/v1.4.0" + "time" +) + +// RegisterTracing enables code tracing via OpenTelemetry. +func RegisterTracing(ctx context.Context, log logr.Logger) error { + tp, err := otlpTracerProvider(ctx, "opentelemetry-collector:4317") + if err != nil { + return err + } + fmt.Println("Begin registering opentelemetry") + otel.SetTracerProvider(tp) + tracing.Register(NewOpenTelemetryAutorestTracer(tele.Tracer())) + + go func() { + <-ctx.Done() + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + if err := tp.Shutdown(ctx); err != nil { + log.Error(err, "failed to shut down tracer provider") + } + }() + + return nil +} + +// otlpTracerProvider initializes an OTLP exporter and configures the corresponding tracer provider. +func otlpTracerProvider(ctx context.Context, url string) (*sdktrace.TracerProvider, error) { + res, err := resource.New(ctx, + resource.WithAttributes( + semconv.ServiceNameKey.String("capo"), + attribute.String("exporter", "otlp"), + ), + ) + fmt.Printf("Set Tracer Provider") + + if err != nil { + return nil, errors.Wrap(err, "failed to create opentelemetry resource") + } + + traceExporter, err := otlptracegrpc.New(ctx, + otlptracegrpc.WithInsecure(), + otlptracegrpc.WithEndpoint(url), + ) + if err != nil { + return nil, errors.Wrap(err, "failed to create otlp trace exporter") + } + + bsp := sdktrace.NewBatchSpanProcessor(traceExporter) + tracerProvider := sdktrace.NewTracerProvider( + sdktrace.WithSampler(sdktrace.AlwaysSample()), + sdktrace.WithResource(res), + sdktrace.WithSpanProcessor(bsp), + ) + otel.SetTracerProvider(tracerProvider) + otel.SetTextMapPropagator(propagation.TraceContext{}) + + return tracerProvider, nil +} diff --git a/cloud/services/security/securitygroup.go b/cloud/services/security/securitygroup.go index a6be52d33..c5005b120 100644 --- a/cloud/services/security/securitygroup.go +++ b/cloud/services/security/securitygroup.go @@ -228,7 +228,7 @@ func (s *Service) GetSecurityGroupFromSecurityGroupRule(securityGroupId string, } else if securityGroupMemberId != "" && ipRanges != "" { return nil, errors.New("Get Both IpRange and securityGroupMemberId") } else { - fmt.Printf("Have IpRange and no securityGroupMemberId\n") + fmt.Printf("Have IpRange and no securityGroupMemberId \n") } oscApiClient := s.scope.GetApi() diff --git a/controllers/osccluster_controller.go b/controllers/osccluster_controller.go index 853b110db..6705d6628 100644 --- a/controllers/osccluster_controller.go +++ b/controllers/osccluster_controller.go @@ -20,16 +20,14 @@ import ( "context" "fmt" infrastructurev1beta1 "github.com/outscale-dev/cluster-api-provider-outscale.git/api/v1beta1" + "github.com/outscale-dev/cluster-api-provider-outscale.git/cloud/scope" "github.com/outscale-dev/cluster-api-provider-outscale.git/cloud/services/net" "github.com/outscale-dev/cluster-api-provider-outscale.git/cloud/services/security" "github.com/outscale-dev/cluster-api-provider-outscale.git/cloud/services/service" + "github.com/outscale-dev/cluster-api-provider-outscale.git/util/reconciler" + "github.com/outscale-dev/cluster-api-provider-outscale.git/util/tele" apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/client-go/tools/record" - "strings" - "time" - - "github.com/outscale-dev/cluster-api-provider-outscale.git/cloud/scope" - "github.com/outscale-dev/cluster-api-provider-outscale.git/util/reconciler" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" "sigs.k8s.io/cluster-api/util" "sigs.k8s.io/cluster-api/util/annotations" @@ -39,6 +37,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/reconcile" + "strings" + "time" ) // OscClusterReconciler reconciles a OscCluster object @@ -100,6 +100,16 @@ func (r *OscClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) _ = log.FromContext(ctx) ctx, cancel := context.WithTimeout(ctx, reconciler.DefaultedLoopTimeout(r.ReconcileTimeout)) defer cancel() + + ctx, _, reconcileDone := tele.StartSpanWithLogger( + ctx, + "controllers.OscClusterReconciler.Reconcile", + tele.KVP("namespace", req.Namespace), + tele.KVP("name", req.Name), + tele.KVP("kind", "OscCluster"), + ) + defer reconcileDone() + log := ctrl.LoggerFrom(ctx) oscCluster := &infrastructurev1beta1.OscCluster{} @@ -181,6 +191,7 @@ func (r *OscClusterReconciler) reconcile(ctx context.Context, clusterScope *scop if err := clusterScope.PatchObject(); err != nil { return reconcile.Result{}, err } + // Check that every element of the cluster spec has the good format (CIDR, Tag, ...) netName, err := checkNetFormatParameters(clusterScope) if err != nil { @@ -290,65 +301,92 @@ func (r *OscClusterReconciler) reconcile(ctx context.Context, clusterScope *scop clusterScope.Info("Set OscCluster status to not ready") clusterScope.SetNotReady() // Reconcile each element of the cluster + ctx, _, netDone := tele.StartSpanWithLogger(ctx, "controllers.OscClusterControllers.netReconcile") + netSvc := r.getNetSvc(ctx, *clusterScope) reconcileNet, err := reconcileNet(ctx, clusterScope, netSvc) if err != nil { clusterScope.Error(err, "failed to reconcile net") conditions.MarkFalse(osccluster, infrastructurev1beta1.NetReadyCondition, infrastructurev1beta1.NetReconciliationFailedReason, clusterv1.ConditionSeverityWarning, err.Error()) + netDone() return reconcileNet, err } + netDone() conditions.MarkTrue(osccluster, infrastructurev1beta1.NetReadyCondition) + ctx, _, subnetDone := tele.StartSpanWithLogger(ctx, "controllers.OscClusterControllers.subnetReconcile") + subnetSvc := r.getSubnetSvc(ctx, *clusterScope) reconcileSubnets, err := reconcileSubnet(ctx, clusterScope, subnetSvc) if err != nil { clusterScope.Error(err, "failed to reconcile subnet") conditions.MarkFalse(osccluster, infrastructurev1beta1.SubnetsReadyCondition, infrastructurev1beta1.SubnetsReconciliationFailedReason, clusterv1.ConditionSeverityWarning, err.Error()) + subnetDone() return reconcileSubnets, err } + subnetDone() conditions.MarkTrue(osccluster, infrastructurev1beta1.SubnetsReadyCondition) + ctx, _, internetServiceDone := tele.StartSpanWithLogger(ctx, "controllers.OscClusterControllers.internetServiceReconcile") + internetServiceSvc := r.getInternetServiceSvc(ctx, *clusterScope) reconcileInternetService, err := reconcileInternetService(ctx, clusterScope, internetServiceSvc) if err != nil { clusterScope.Error(err, "failed to reconcile internetService") conditions.MarkFalse(osccluster, infrastructurev1beta1.InternetServicesReadyCondition, infrastructurev1beta1.InternetServicesFailedReason, clusterv1.ConditionSeverityWarning, err.Error()) + internetServiceDone() return reconcileInternetService, err } + internetServiceDone() conditions.MarkTrue(osccluster, infrastructurev1beta1.InternetServicesReadyCondition) + ctx, _, publicIpDone := tele.StartSpanWithLogger(ctx, "controllers.OscClusterControllers.publicIpReconcile") + publicIpSvc := r.getPublicIpSvc(ctx, *clusterScope) reconcilePublicIp, err := reconcilePublicIp(ctx, clusterScope, publicIpSvc) if err != nil { clusterScope.Error(err, "failed to reconcile publicIp") conditions.MarkFalse(osccluster, infrastructurev1beta1.PublicIpsReadyCondition, infrastructurev1beta1.PublicIpsFailedReason, clusterv1.ConditionSeverityWarning, err.Error()) + publicIpDone() return reconcilePublicIp, err } + publicIpDone() conditions.MarkTrue(osccluster, infrastructurev1beta1.PublicIpsReadyCondition) + ctx, _, securityGroupDone := tele.StartSpanWithLogger(ctx, "controllers.OscClusterControllers.securityGroupReconcile") + securityGroupSvc := r.getSecurityGroupSvc(ctx, *clusterScope) reconcileSecurityGroups, err := reconcileSecurityGroup(ctx, clusterScope, securityGroupSvc) if err != nil { clusterScope.Error(err, "failed to reconcile securityGroup") conditions.MarkFalse(osccluster, infrastructurev1beta1.SecurityGroupReadyCondition, infrastructurev1beta1.SecurityGroupReconciliationFailedReason, clusterv1.ConditionSeverityWarning, err.Error()) + securityGroupDone() return reconcileSecurityGroups, err } + securityGroupDone() conditions.MarkTrue(osccluster, infrastructurev1beta1.SecurityGroupReadyCondition) + ctx, _, routeTableDone := tele.StartSpanWithLogger(ctx, "controller.OscClusterControllers.routeTableReconcile") + routeTableSvc := r.getRouteTableSvc(ctx, *clusterScope) reconcileRouteTables, err := reconcileRouteTable(ctx, clusterScope, routeTableSvc) if err != nil { clusterScope.Error(err, "failed to reconcile routeTable") conditions.MarkFalse(osccluster, infrastructurev1beta1.RouteTablesReadyCondition, infrastructurev1beta1.RouteTableReconciliationFailedReason, clusterv1.ConditionSeverityWarning, err.Error()) + routeTableDone() return reconcileRouteTables, err } + routeTableDone() conditions.MarkTrue(osccluster, infrastructurev1beta1.RouteTablesReadyCondition) + ctx, _, natServiceDone := tele.StartSpanWithLogger(ctx, "controller.OscClusterControllers.natServiceReconcile") + natServiceSvc := r.getNatServiceSvc(ctx, *clusterScope) reconcileNatService, err := reconcileNatService(ctx, clusterScope, natServiceSvc) if err != nil { clusterScope.Error(err, "failed to reconcile natservice") conditions.MarkFalse(osccluster, infrastructurev1beta1.NatServicesReadyCondition, infrastructurev1beta1.NatServicesReconciliationFailedReason, clusterv1.ConditionSeverityWarning, err.Error()) + natServiceDone() return reconcileNatService, nil } conditions.MarkTrue(osccluster, infrastructurev1beta1.NatServicesReadyCondition) @@ -357,13 +395,17 @@ func (r *OscClusterReconciler) reconcile(ctx context.Context, clusterScope *scop if err != nil { clusterScope.Error(err, "failed to reconcile NatRouteTable") conditions.MarkFalse(osccluster, infrastructurev1beta1.RouteTablesReadyCondition, infrastructurev1beta1.RouteTableReconciliationFailedReason, clusterv1.ConditionSeverityWarning, err.Error()) + natServiceDone() return reconcileNatRouteTable, err } + natServiceDone() conditions.MarkTrue(osccluster, infrastructurev1beta1.RouteTablesReadyCondition) + ctx, _, loadBalancerDone := tele.StartSpanWithLogger(ctx, "controllers.OscClusterControllers.loadBalancerReconcile") + loadBalancerSvc := r.getLoadBalancerSvc(ctx, *clusterScope) _, err = reconcileLoadBalancer(ctx, clusterScope, loadBalancerSvc) - + loadBalancerDone() clusterScope.Info("Set OscCluster status to ready") clusterScope.SetReady() return reconcile.Result{}, nil @@ -390,52 +432,85 @@ func (r *OscClusterReconciler) reconcileDelete(ctx context.Context, clusterScope return reconcile.Result{RequeueAfter: 10 * time.Second}, nil } + ctx, _, loadBalancerDone := tele.StartSpanWithLogger(ctx, "controllers.OscMachineReconciler.reconcileLoadBalancerDelete") + loadBalancerSvc := r.getLoadBalancerSvc(ctx, *clusterScope) reconcileDeleteLoadBalancer, err := reconcileDeleteLoadBalancer(ctx, clusterScope, loadBalancerSvc) if err != nil { + loadBalancerDone() return reconcileDeleteLoadBalancer, err } + loadBalancerDone() + + ctx, _, natServiceDone := tele.StartSpanWithLogger(ctx, "controllers.OscMachineReconciler.reconcileNatServiceDelete") natServiceSvc := r.getNatServiceSvc(ctx, *clusterScope) reconcileDeleteNatService, err := reconcileDeleteNatService(ctx, clusterScope, natServiceSvc) if err != nil { + natServiceDone() return reconcileDeleteNatService, err } + natServiceDone() + ctx, _, publicIpDone := tele.StartSpanWithLogger(ctx, "controllers.OscMachineReconciler.reconcilePublicIpDelete") publicIpSvc := r.getPublicIpSvc(ctx, *clusterScope) reconcileDeletePublicIp, err := reconcileDeletePublicIp(ctx, clusterScope, publicIpSvc) if err != nil { + publicIpDone() return reconcileDeletePublicIp, err } + publicIpDone() + + ctx, _, routeTableDone := tele.StartSpanWithLogger(ctx, "controllers.OscMachineReconciler.reconcileRouteTableDelete") + routeTableSvc := r.getRouteTableSvc(ctx, *clusterScope) reconcileDeleteRouteTable, err := reconcileDeleteRouteTable(ctx, clusterScope, routeTableSvc) if err != nil { + routeTableDone() return reconcileDeleteRouteTable, err } + routeTableDone() + + ctx, _, securityGroupDone := tele.StartSpanWithLogger(ctx, "controllers.OscMachineReconciler.reconcileSecurityGroupDelete") securityGroupSvc := r.getSecurityGroupSvc(ctx, *clusterScope) reconcileDeleteSecurityGroup, err := reconcileDeleteSecurityGroup(ctx, clusterScope, securityGroupSvc) if err != nil { + securityGroupDone() return reconcileDeleteSecurityGroup, err } + securityGroupDone() + + ctx, _, internetServiceGroupDone := tele.StartSpanWithLogger(ctx, "controllers.OscMachineReconciler.reconcileInternetServiceGroupDelete") internetServiceSvc := r.getInternetServiceSvc(ctx, *clusterScope) reconcileDeleteInternetService, err := reconcileDeleteInternetService(ctx, clusterScope, internetServiceSvc) if err != nil { + internetServiceGroupDone() return reconcileDeleteInternetService, err } + internetServiceGroupDone() + + ctx, _, subnetDone := tele.StartSpanWithLogger(ctx, "controllers.OscMachineReconciler.reconcileSubnetDelete") subnetSvc := r.getSubnetSvc(ctx, *clusterScope) reconcileDeleteSubnet, err := reconcileDeleteSubnet(ctx, clusterScope, subnetSvc) if err != nil { + subnetDone() return reconcileDeleteSubnet, err } + subnetDone() + + ctx, _, netDone := tele.StartSpanWithLogger(ctx, "controllers.OscMachineReconciler.reconcileNetDelete") netSvc := r.getNetSvc(ctx, *clusterScope) reconcileDeleteNet, err := reconcileDeleteNet(ctx, clusterScope, netSvc) if err != nil { + netDone() return reconcileDeleteNet, err } + netDone() + controllerutil.RemoveFinalizer(osccluster, "oscclusters.infrastructure.cluster.x-k8s.io") return reconcile.Result{}, nil } diff --git a/controllers/oscmachine_controller.go b/controllers/oscmachine_controller.go index 02617f6c8..6cd6281fa 100644 --- a/controllers/oscmachine_controller.go +++ b/controllers/oscmachine_controller.go @@ -26,6 +26,7 @@ import ( "github.com/outscale-dev/cluster-api-provider-outscale.git/cloud/services/service" "github.com/outscale-dev/cluster-api-provider-outscale.git/cloud/services/storage" "github.com/outscale-dev/cluster-api-provider-outscale.git/util/reconciler" + "github.com/outscale-dev/cluster-api-provider-outscale.git/util/tele" "github.com/pkg/errors" apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/client-go/tools/record" @@ -111,6 +112,15 @@ func (r *OscMachineReconciler) Reconcile(ctx context.Context, req ctrl.Request) ctx, cancel := context.WithTimeout(ctx, reconciler.DefaultedLoopTimeout(r.ReconcileTimeout)) defer cancel() + ctx, _, done := tele.StartSpanWithLogger( + ctx, + "controllers.OscMachineReconciler.Reconcile", + tele.KVP("namespace", req.Namespace), + tele.KVP("name", req.Name), + tele.KVP("kind", "OscMachine"), + ) + defer done() + log := ctrl.LoggerFrom(ctx) oscMachine := &infrastructurev1beta1.OscMachine{} @@ -186,6 +196,9 @@ func (r *OscMachineReconciler) Reconcile(ctx context.Context, req ctrl.Request) // reconcile reconcile the creation of the machine func (r *OscMachineReconciler) reconcile(ctx context.Context, machineScope *scope.MachineScope, clusterScope *scope.ClusterScope) (reconcile.Result, error) { machineScope.Info("Reconciling OscMachine") + ctx, _, machineDone := tele.StartSpanWithLogger(ctx, "controllers.OscMachineReconciler.reconcile") + defer machineDone() + oscmachine := machineScope.OscMachine if oscmachine.Status.FailureReason != nil || oscmachine.Status.FailureMessage != nil { machineScope.Info("Error state detected, skipping reconciliation") @@ -276,13 +289,18 @@ func (r *OscMachineReconciler) reconcile(ctx context.Context, machineScope *scop return reconcile.Result{}, checkVmVolumeSubregionNameErr } } - + ctx, _, imageDone := tele.StartSpanWithLogger(ctx, "controllers.OscMachineController.imageReconcile") imageSvc := r.getImageSvc(ctx, *clusterScope) + reconcileImage, err := reconcileImage(ctx, machineScope, imageSvc) if err != nil { machineScope.Error(err, "failed to reconcile Image") + imageDone() return reconcileImage, err } + imageDone() + + ctx, _, volumeDone := tele.StartSpanWithLogger(ctx, "controllers.OscMachineControllers.VolumeReconcile") volumeSvc := r.getVolumeSvc(ctx, *clusterScope) if len(machineScope.OscMachine.Spec.Node.Volumes) > 0 { @@ -291,27 +309,46 @@ func (r *OscMachineReconciler) reconcile(ctx context.Context, machineScope *scop if err != nil { machineScope.Error(err, "failed to reconcile volume") conditions.MarkFalse(oscmachine, infrastructurev1beta1.VolumeReadyCondition, infrastructurev1beta1.VolumeReconciliationFailedReason, clusterv1.ConditionSeverityWarning, err.Error()) + volumeDone() return reconcileVolume, err } } + volumeDone() + + ctx, _, keypairDone := tele.StartSpanWithLogger(ctx, "controllers.OscMachineControllers.KeypairReconcile") keypairSvc := r.getKeyPairSvc(ctx, *clusterScope) reconcileKeypair, err := reconcileKeypair(ctx, machineScope, keypairSvc) if err != nil { machineScope.Error(err, "failed to reconcile keypair") + keypairDone() return reconcileKeypair, err } + keypairDone() + + ctx, _, publicIpDone := tele.StartSpanWithLogger(ctx, "controllers.OscMachineControllers.PublicIpReconcile") publicIpSvc := r.getPublicIpSvc(ctx, *clusterScope) + publicIpDone() + ctx, _, vmDone := tele.StartSpanWithLogger(ctx, "controllers.OscMachineControllers.VmReconcile") + vmSvc := r.getVmSvc(ctx, *clusterScope) + ctx, _, loadBalancerDone := tele.StartSpanWithLogger(ctx, "controllers.OscMachineControllers.LoadBalancerReconcile") + loadBalancerSvc := r.getLoadBalancerSvc(ctx, *clusterScope) + loadBalancerDone() + ctx, _, securityGroupDone := tele.StartSpanWithLogger(ctx, "controllers.OscMachineControllers.SecurityGroupReconcile") + securityGroupSvc := r.getSecurityGroupSvc(ctx, *clusterScope) + securityGroupDone() reconcileVm, err := reconcileVm(ctx, clusterScope, machineScope, vmSvc, volumeSvc, publicIpSvc, loadBalancerSvc, securityGroupSvc) if err != nil { machineScope.Error(err, "failed to reconcile vm") conditions.MarkFalse(oscmachine, infrastructurev1beta1.VmReadyCondition, infrastructurev1beta1.VmNotReadyReason, clusterv1.ConditionSeverityWarning, err.Error()) + vmDone() return reconcileVm, err } + vmDone() conditions.MarkTrue(oscmachine, infrastructurev1beta1.VolumeReadyCondition) vmState := machineScope.GetVmState() @@ -346,6 +383,9 @@ func (r *OscMachineReconciler) reconcile(ctx context.Context, machineScope *scop // reconcileDelete reconcile the deletion of the machine func (r *OscMachineReconciler) reconcileDelete(ctx context.Context, machineScope *scope.MachineScope, clusterScope *scope.ClusterScope) (reconcile.Result, error) { machineScope.Info("Reconciling delete OscMachine") + ctx, _, reconcileDeleteDone := tele.StartSpanWithLogger(ctx, "controllers.OscMachineReconciler.reconcileDelete") + defer reconcileDeleteDone() + oscmachine := machineScope.OscMachine if len(machineScope.OscMachine.Spec.Node.Volumes) > 0 { machineScope.Info("Find volumes") @@ -355,25 +395,50 @@ func (r *OscMachineReconciler) reconcileDelete(ctx context.Context, machineScope return reconcileDeleteVolume, err } } + + ctx, _, publicIpDone := tele.StartSpanWithLogger(ctx, "controllers.OscMachineReconciler.reconcilePublicIpDelete") + publicIpSvc := r.getPublicIpSvc(ctx, *clusterScope) + publicIpDone() + ctx, _, vmDone := tele.StartSpanWithLogger(ctx, "controllers.OscMachineReconciler.reconcileVmDelete") + vmSvc := r.getVmSvc(ctx, *clusterScope) + ctx, _, loadBalancerDone := tele.StartSpanWithLogger(ctx, "controllers.OscMachineReconciler.reconcileLoadBalancerDelete") + loadBalancerSvc := r.getLoadBalancerSvc(ctx, *clusterScope) + loadBalancerDone() + ctx, _, securityGroupDone := tele.StartSpanWithLogger(ctx, "controller.OscMachineReconciler.reconcileSecurityGroupDelete") + securityGroupSvc := r.getSecurityGroupSvc(ctx, *clusterScope) + securityGroupDone() reconcileDeleteVm, err := reconcileDeleteVm(ctx, clusterScope, machineScope, vmSvc, publicIpSvc, loadBalancerSvc, securityGroupSvc) if err != nil { + vmDone() return reconcileDeleteVm, err } + vmDone() + + ctx, _, keypairDone := tele.StartSpanWithLogger(ctx, "controller.OscMachineReconciler.reconcileKeyypairDelete") + keypairSvc := r.getKeyPairSvc(ctx, *clusterScope) reconcileDeleteKeyPair, err := reconcileDeleteKeypair(ctx, machineScope, keypairSvc) if err != nil { + keypairDone() return reconcileDeleteKeyPair, err } + keypairDone() controllerutil.RemoveFinalizer(oscmachine, "oscmachine.infrastructure.cluster.x-k8s.io") return reconcile.Result{}, nil } // SetupWithManager sets up the controller with the Manager. func (r *OscMachineReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error { + ctx, _, done := tele.StartSpanWithLogger(ctx, + "controllers.OscMachineReconciler.SetupWithManager", + tele.KVP("controller", "OscMachine"), + ) + defer done() + clusterToObjectFunc, err := util.ClusterToObjectsMapper(r.Client, &infrastructurev1beta1.OscMachineList{}, mgr.GetScheme()) if err != nil { return errors.Errorf("failed to create mapper for Cluster to OscMachines: %+v", err) diff --git a/go.mod b/go.mod index b0c27e975..aae12d470 100644 --- a/go.mod +++ b/go.mod @@ -4,14 +4,14 @@ go 1.18 require ( github.com/Jeffail/gabs v1.4.0 - github.com/benbjohnson/clock v1.1.0 - github.com/go-logr/logr v1.2.2 + github.com/benbjohnson/clock v1.3.0 + github.com/go-logr/logr v1.2.3 github.com/golang/mock v1.6.0 github.com/onsi/ginkgo v1.16.5 github.com/onsi/gomega v1.17.0 github.com/outscale/osc-sdk-go/v2 v2.8.0 github.com/pkg/errors v0.9.1 - github.com/stretchr/testify v1.7.0 + github.com/stretchr/testify v1.8.0 golang.org/x/exp v0.0.0-20220907003533-145caa8ea1d0 golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd k8s.io/api v0.23.5 @@ -23,6 +23,16 @@ require ( sigs.k8s.io/controller-runtime v0.11.2 ) +require ( + github.com/cenkalti/backoff/v4 v4.1.2 // indirect + github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.4.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.4.0 // indirect + go.opentelemetry.io/otel/internal/metric v0.27.0 // indirect + go.opentelemetry.io/proto/otlp v0.12.0 // indirect + google.golang.org/grpc v1.44.0 // indirect +) + require ( github.com/BurntSushi/toml v1.0.0 // indirect github.com/MakeNowJust/heredoc v1.0.0 // indirect @@ -42,6 +52,8 @@ require ( github.com/docker/go-connections v0.4.0 // indirect github.com/docker/go-units v0.4.0 // indirect github.com/drone/envsubst/v2 v2.0.0-20210730161058-179042472c46 // indirect + github.com/felixge/httpsnoop v1.0.3 // indirect + github.com/go-logr/stdr v1.2.2 // indirect github.com/go-openapi/jsonpointer v0.19.5 // indirect github.com/go-openapi/jsonreference v0.19.5 // indirect github.com/go-openapi/swag v0.19.14 // indirect @@ -71,6 +83,14 @@ require ( github.com/stoewer/go-strcase v1.2.0 // indirect github.com/subosito/gotenv v1.2.0 // indirect github.com/valyala/fastjson v1.6.3 // indirect + go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.27.0 + go.opentelemetry.io/otel v1.4.0 + go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.4.0 + go.opentelemetry.io/otel/exporters/prometheus v0.27.0 + go.opentelemetry.io/otel/metric v0.27.0 + go.opentelemetry.io/otel/sdk v1.4.0 + go.opentelemetry.io/otel/sdk/metric v0.27.0 + go.opentelemetry.io/otel/trace v1.4.0 gopkg.in/ini.v1 v1.63.2 // indirect k8s.io/apiserver v0.23.5 // indirect sigs.k8s.io/kind v0.14.0 // indirect @@ -83,11 +103,11 @@ require ( github.com/Azure/go-autorest/autorest/adal v0.9.13 // indirect github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect github.com/Azure/go-autorest/logger v0.2.1 // indirect - github.com/Azure/go-autorest/tracing v0.6.0 // indirect + github.com/Azure/go-autorest/tracing v0.6.0 github.com/aws/aws-sdk-go v1.43.18 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/blang/semver v3.5.1+incompatible // indirect - github.com/cespare/xxhash/v2 v2.1.1 // indirect + github.com/cespare/xxhash/v2 v2.1.2 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/evanphx/json-patch v4.12.0+incompatible // indirect github.com/evanphx/json-patch/v5 v5.6.0 // indirect @@ -100,7 +120,7 @@ require ( github.com/golang/protobuf v1.5.2 // indirect github.com/google/go-cmp v0.5.8 // indirect github.com/google/gofuzz v1.2.0 // indirect - github.com/google/uuid v1.3.0 // indirect + github.com/google/uuid v1.3.0 github.com/googleapis/gnostic v0.5.5 // indirect github.com/imdario/mergo v0.3.12 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect @@ -110,10 +130,10 @@ require ( github.com/modern-go/reflect2 v1.0.2 // indirect github.com/nxadm/tail v1.4.8 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/prometheus/client_golang v1.11.1 // indirect + github.com/prometheus/client_golang v1.12.1 github.com/prometheus/client_model v0.2.0 // indirect github.com/prometheus/common v0.32.1 // indirect - github.com/prometheus/procfs v0.6.0 // indirect + github.com/prometheus/procfs v0.7.3 // indirect github.com/spf13/pflag v1.0.5 // indirect go.uber.org/atomic v1.9.0 // indirect go.uber.org/multierr v1.6.0 // indirect @@ -171,3 +191,5 @@ replace ( k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.23.5 sigs.k8s.io/cluster-api => sigs.k8s.io/cluster-api v1.1.3 ) + +replace go.opentelemetry.io/otel/metric => go.opentelemetry.io/otel/metric v0.27.0 diff --git a/go.sum b/go.sum index c93eb8598..39e3cb7f0 100644 --- a/go.sum +++ b/go.sum @@ -124,8 +124,9 @@ github.com/aws/aws-sdk-go v1.38.49/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2z github.com/aws/aws-sdk-go v1.43.18 h1:nwLaIz2m1f7YBEMNyEc6bBB276AIEaGaIQrc2G9h4zY= github.com/aws/aws-sdk-go v1.43.18/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX4oIKwKHZo= github.com/benbjohnson/clock v1.0.3/go.mod h1:bGMdMPoPVvcYyt1gHDf4J2KE153Yf9BuiUKYMaxlTDM= -github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= +github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A= +github.com/benbjohnson/clock v1.3.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= @@ -138,12 +139,15 @@ github.com/blang/semver v3.5.0+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnweb github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ= github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps= +github.com/cenkalti/backoff/v4 v4.1.2 h1:6Yo7N8UP2K6LWZnW94DLVSSrbobcWdVzAYOisuDPIFo= +github.com/cenkalti/backoff/v4 v4.1.2/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/certifi/gocertifi v0.0.0-20191021191039-0944d244cd40/go.mod h1:sGbDF6GwGcLpkNXPUTkMRoywsNa/ol15pxFe6ERfguA= github.com/certifi/gocertifi v0.0.0-20200922220541-2c3bb06c6054/go.mod h1:sGbDF6GwGcLpkNXPUTkMRoywsNa/ol15pxFe6ERfguA= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= -github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE= +github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/chai2010/gettext-go v0.0.0-20160711120539-c6fed771bfd5/go.mod h1:/iP1qXHoty45bqomnu2LM+VVyAEdWN+vtSHGlQgyxbw= github.com/checkpoint-restore/go-criu/v5 v5.0.0/go.mod h1:cfwC0EG7HMUenopBsUf9d89JlCLQIfgVcNsNN0t6T2M= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= @@ -156,7 +160,11 @@ github.com/clusterhq/flocker-go v0.0.0-20160920122132-2b8b7259d313/go.mod h1:P1w github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= +github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4/go.mod h1:6pvJx4me5XPnfI9Z40ddWsdw2W/uZgQLFXToKeRcDiI= github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/cncf/xds/go v0.0.0-20210805033703-aa0b78936158/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/cockroachdb/datadriven v0.0.0-20200714090401-bf6692d28da5/go.mod h1:h6jFvWxBdQXxjopDMZyH2UVceIRfR84bdzbkoKrsWNo= github.com/cockroachdb/errors v1.2.4/go.mod h1:rQD95gz6FARkaKkQXUksEje/d9a6wBJoCr5oaCLELYA= github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f/go.mod h1:i/u985jwjWRlyHXQbwatDASoW0RMlZ/3i9yJHE2xLkI= @@ -223,6 +231,7 @@ github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5y github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.mod h1:hliV/p42l8fGbc6Y9bQ70uLwIvmJyVE5k4iMKlh8wCQ= +github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/euank/go-kmsg-parser v2.0.0+incompatible/go.mod h1:MhmAMZ8V4CYH4ybgdRwPr2TU5ThnS43puaKEMpja1uw= github.com/evanphx/json-patch v0.5.2/go.mod h1:ZWS5hhDbVDyob71nXKNL0+PWn6ToqBHMikGIFbs31qQ= @@ -236,6 +245,9 @@ github.com/fatih/camelcase v1.0.0/go.mod h1:yN2Sb0lFhZJUdVvtELVWefmrXpuZESvPmqwo github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU= github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= +github.com/felixge/httpsnoop v1.0.2/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= +github.com/felixge/httpsnoop v1.0.3 h1:s/nj+GCswXYzN5v2DpNMuMQYe+0DDwt5WVCU6CWBdXk= +github.com/felixge/httpsnoop v1.0.3/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k= github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k= @@ -263,8 +275,11 @@ github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas= github.com/go-logr/logr v0.2.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU= github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-logr/logr v1.2.2 h1:ahHml/yUpnlb96Rp8HCvtYVPY8ZYpxq3g7UYchIYwbs= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0= +github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-logr/zapr v1.2.0 h1:n4JnPI1T3Qq1SFEi/F8rwLrZERp2bso19PJZDB9dayk= github.com/go-logr/zapr v1.2.0/go.mod h1:Qa4Bsj2Vb+FAVeAKsLD8RLQ+YRJB8YDmOAKxaBQf7Ro= github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= @@ -347,6 +362,7 @@ github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-github/v33 v33.0.0 h1:qAf9yP0qc54ufQxzwv+u9H0tiVOnPJxo0lI/JXqw3ZM= @@ -400,6 +416,7 @@ github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmg github.com/grpc-ecosystem/go-grpc-middleware v1.3.0/go.mod h1:z0ButlSOZa5vEBq9m2m2hlwIgKw+rp3sdCBRoJY+30Y= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= +github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q= github.com/hashicorp/consul/api v1.10.1/go.mod h1:XjsvQN+RJGWI2TWy1/kqaE16HrR2J/FWgkYjdZQsX9M= @@ -611,8 +628,8 @@ github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDf github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M= github.com/prometheus/client_golang v1.11.0/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0= -github.com/prometheus/client_golang v1.11.1 h1:+4eQaD7vAZ6DsfsxB15hbE0odUjGI5ARs9yskGu1v4s= -github.com/prometheus/client_golang v1.11.1/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0= +github.com/prometheus/client_golang v1.12.1 h1:ZiaPsmm9uiBeaSMRznKsCDNtPCS0T3JVDGF+06gjBzk= +github.com/prometheus/client_golang v1.12.1/go.mod h1:3Z9XVyYiZYEO+YQWt3RD2R3jrbd179Rt297l4aS6nDY= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= @@ -631,8 +648,9 @@ github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7z github.com/prometheus/procfs v0.0.0-20190522114515-bc1a522cf7b1/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= -github.com/prometheus/procfs v0.6.0 h1:mxy4L2jP6qMonqmq+aTtOx1ifVWUgG/TAmntgbh3xv4= github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= +github.com/prometheus/procfs v0.7.3 h1:4jVXhlkAyzOScmCkXBTOLRLTz8EeU+eyjrwB/EPq0VU= +github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= github.com/quobyte/api v0.1.8/go.mod h1:jL7lIHrmqQ7yh05OJ+eEEdHr0u/kmT1Ff9iHd+4H6VI= github.com/remyoudompheng/bigfft v0.0.0-20170806203942-52369c62f446/go.mod h1:uYEyJGbgTkfkS4+E/PavXkNJcbFIpEtjt2B0KDQ5+9M= @@ -699,13 +717,16 @@ github.com/storageos/go-api v2.2.0+incompatible/go.mod h1:ZrLn+e0ZuF3Y65PNF6dIwb github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww= @@ -749,15 +770,40 @@ go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E= go.opentelemetry.io/contrib v0.20.0/go.mod h1:G/EtFaa6qaN7+LxqfIAT3GiZa7Wv5DTBUzl5H4LY0Kc= go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.20.0/go.mod h1:oVGt1LRbBOBq1A5BQLlUg9UaU/54aiHw8cgjV3aWZ/E= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.20.0/go.mod h1:2AboqHi0CiIZU0qwhtUfCYD1GeUzvvIXWNkhDt7ZMG4= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.27.0 h1:0BgiNWjN7rUWO9HdjF4L12r8OW86QkVQcYmCjnayJLo= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.27.0/go.mod h1:bdvm3YpMxWAgEfQhtTBaVR8ceXPRuRBSQrvOBnIlHxc= go.opentelemetry.io/otel v0.20.0/go.mod h1:Y3ugLH2oa81t5QO+Lty+zXf8zC9L26ax4Nzoxm/dooo= +go.opentelemetry.io/otel v1.2.0/go.mod h1:aT17Fk0Z1Nor9e0uisf98LrntPGMnk4frBO9+dkf69I= +go.opentelemetry.io/otel v1.4.0 h1:7ESuKPq6zpjRaY5nvVDGiuwK7VAJ8MwkKnmNJ9whNZ4= +go.opentelemetry.io/otel v1.4.0/go.mod h1:jeAqMFKy2uLIxCtKxoFj0FAL5zAPKQagc3+GtBWakzk= go.opentelemetry.io/otel/exporters/otlp v0.20.0/go.mod h1:YIieizyaN77rtLJra0buKiNBOm9XQfkPEKBeuhoMwAM= -go.opentelemetry.io/otel/metric v0.20.0/go.mod h1:598I5tYlH1vzBjn+BTuhzTCSb/9debfNp6R3s7Pr1eU= +go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.4.0 h1:j7AwzDdAQBJjcqayAaYbvpYeZzII7cEe5qJTu+De6UY= +go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.4.0/go.mod h1:VpP4/RMn8bv8gNo9uK7/IMY4mtWLELsS+JIP0inH0h4= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.4.0 h1:lRpP10E8oTGVmY1nVXcwelCT1Z8ca41/l5ce7AqLAss= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.4.0/go.mod h1:3oS+j2WUoJVyj6/BzQN/52G17lNJDulngsOxDm1w2PY= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.4.0 h1:buSx4AMC/0Z232slPhicN/fU5KIlj0bMngct5pcZhkI= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.4.0/go.mod h1:ew1NcwkHo0QFT3uTm3m2IVZMkZdVIpbOYNPasgWwpdk= +go.opentelemetry.io/otel/exporters/prometheus v0.27.0 h1:HcGi6HmYRuszR3stcvN2GctJjQtvp44nw/VdfJCo/Ec= +go.opentelemetry.io/otel/exporters/prometheus v0.27.0/go.mod h1:u0vTzijx2B6gGDa8FuIVoESW6z0HdKkXZWZMSTsoJKs= +go.opentelemetry.io/otel/internal/metric v0.27.0 h1:9dAVGAfFiiEq5NVB9FUJ5et+btbDQAUIJehJ+ikyryk= +go.opentelemetry.io/otel/internal/metric v0.27.0/go.mod h1:n1CVxRqKqYZtqyTh9U/onvKapPGv7y/rpyOTI+LFNzw= +go.opentelemetry.io/otel/metric v0.27.0 h1:HhJPsGhJoKRSegPQILFbODU56NS/L1UE4fS1sC5kIwQ= +go.opentelemetry.io/otel/metric v0.27.0/go.mod h1:raXDJ7uP2/Jc0nVZWQjJtzoyssOYWu/+pjZqRzfvZ7g= go.opentelemetry.io/otel/oteltest v0.20.0/go.mod h1:L7bgKf9ZB7qCwT9Up7i9/pn0PWIa9FqQ2IQ8LoxiGnw= go.opentelemetry.io/otel/sdk v0.20.0/go.mod h1:g/IcepuwNsoiX5Byy2nNV0ySUF1em498m7hBWC279Yc= +go.opentelemetry.io/otel/sdk v1.4.0 h1:LJE4SW3jd4lQTESnlpQZcBhQ3oci0U2MLR5uhicfTHQ= +go.opentelemetry.io/otel/sdk v1.4.0/go.mod h1:71GJPNJh4Qju6zJuYl1CrYtXbrgfau/M9UAggqiy1UE= go.opentelemetry.io/otel/sdk/export/metric v0.20.0/go.mod h1:h7RBNMsDJ5pmI1zExLi+bJK+Dr8NQCh0qGhm1KDnNlE= go.opentelemetry.io/otel/sdk/metric v0.20.0/go.mod h1:knxiS8Xd4E/N+ZqKmUPf3gTTZ4/0TjTXukfxjzSTpHE= +go.opentelemetry.io/otel/sdk/metric v0.27.0 h1:CDEu96Js5IP7f4bJ8eimxF09V5hKYmE7CeyKSjmAL1s= +go.opentelemetry.io/otel/sdk/metric v0.27.0/go.mod h1:lOgrT5C3ORdbqp2LsDrx+pBj6gbZtQ5Omk27vH3EaW0= go.opentelemetry.io/otel/trace v0.20.0/go.mod h1:6GjCW8zgDjwGHGa6GkyeB8+/5vjT16gUEi0Nf1iBdgw= +go.opentelemetry.io/otel/trace v1.2.0/go.mod h1:N5FLswTubnxKxOJHM7XZC074qpeEdLy3CgAVsdMucK0= +go.opentelemetry.io/otel/trace v1.4.0 h1:4OOUrPZdVFQkbzl/JSdvGCWIdw5ONXXxzHlaLlWppmo= +go.opentelemetry.io/otel/trace v1.4.0/go.mod h1:uc3eRsqDfWs9R7b92xbQbU42/eTNz4N+gLP8qJCi4aE= go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= +go.opentelemetry.io/proto/otlp v0.12.0 h1:CMJ/3Wp7iOWES+CYLfnBv+DVmPbB+kmy9PJ92XvlR6c= +go.opentelemetry.io/proto/otlp v0.12.0/go.mod h1:TsIjwGWIx5VFYv9KGVlOpxoBl5Dy+63SUguV7GGvlSQ= go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5/go.mod h1:nmDLcffg48OtT/PSW0Hg7FvpRQsQh5OSqIylirxKC7o= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= @@ -766,6 +812,7 @@ go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A= go.uber.org/goleak v1.1.11-0.20210813005559-691160354723/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= go.uber.org/goleak v1.1.12 h1:gZAh5/EyT/HQwlpkCy6wTpqfH9H8Lz8zbm3dZh+OyzA= +go.uber.org/goleak v1.1.12/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= @@ -994,6 +1041,7 @@ golang.org/x/sys v0.0.0-20210324051608-47abb6519492/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210426230700-d19ff857e887/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210503080704-8803ae5d1324/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -1010,6 +1058,7 @@ golang.org/x/sys v0.0.0-20210831042530-f4d43177bf5e/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210908233432-aa78b53d3365/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= @@ -1240,6 +1289,9 @@ google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQ google.golang.org/grpc v1.39.0/go.mod h1:PImNr+rS9TWYb2O4/emRugxiyHZ5JyHW5F+RPnDzfrE= google.golang.org/grpc v1.39.1/go.mod h1:PImNr+rS9TWYb2O4/emRugxiyHZ5JyHW5F+RPnDzfrE= google.golang.org/grpc v1.40.0/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34= +google.golang.org/grpc v1.43.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ590SU= +google.golang.org/grpc v1.44.0 h1:weqSxi/TMs1SqFRMHCtBgXRs8k3X39QIDEZ0pRcttUg= +google.golang.org/grpc v1.44.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ590SU= google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= diff --git a/main.go b/main.go index ce6a52290..de1f4df55 100644 --- a/main.go +++ b/main.go @@ -37,6 +37,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/log/zap" infrastructurev1beta1 "github.com/outscale-dev/cluster-api-provider-outscale.git/api/v1beta1" + "github.com/outscale-dev/cluster-api-provider-outscale.git/cloud/opentracing" "github.com/outscale-dev/cluster-api-provider-outscale.git/controllers" //+kubebuilder:scaffold:imports ) @@ -45,6 +46,7 @@ var ( scheme = runtime.NewScheme() setupLog = ctrl.Log.WithName("setup") reconcileTimeout time.Duration + enableTracing bool ) func init() { @@ -64,6 +66,7 @@ func main() { flag.BoolVar(&enableLeaderElection, "leader-elect", true, "Enable leader election for controller manager. "+ "Enabling this will ensure there is only one active controller manager.") + flag.BoolVar(&enableTracing, "enable-tracing", false, "Enable tracing to the opentelemetry-collector service in the same namespace.") opts := zap.Options{ Development: true, } @@ -99,7 +102,16 @@ func main() { os.Exit(1) } - ctx := ctrl.SetupSignalHandler() + ctx := ctrl.SetupSignalHandler() + if err := opentracing.RegisterTracing(ctx, setupLog); err != nil { + setupLog.Error(err, "unable to initialize tracing") + os.Exit(1) + } + + if err := opentracing.RegisterMetrics(); err != nil { + setupLog.Error(err, "unable to initiliaze metrics") + os.Exit(1) + } if err = (&controllers.OscMachineReconciler{ Client: mgr.GetClient(), diff --git a/util/tele/composite_logger.go b/util/tele/composite_logger.go new file mode 100644 index 000000000..a9677e4b5 --- /dev/null +++ b/util/tele/composite_logger.go @@ -0,0 +1,80 @@ +package tele + +import ( + "github.com/go-logr/logr" +) + +type compositeLogSink struct { + logSinks []logr.LogSink +} + +// Init CompositeLogSink +func (c *compositeLogSink) Init(info logr.RuntimeInfo) { + info.CallDepth += 2 + for _, l := range c.logSinks { + l.Init(info) + } +} + +// Enable CompositeLogSink +func (c *compositeLogSink) Enabled(v int) bool { + for _, l := range c.logSinks { + if !l.Enabled(v) { + return false + } + } + return true +} + +// Iter CompositeLogSink +func (c *compositeLogSink) iter(fn func(l logr.LogSink)) { + for _, l := range c.logSinks { + fn(l) + } +} + +// Info compositeLogSink +func (c *compositeLogSink) Info(level int, msg string, keysAndValues ...interface{}) { + c.iter(func(l logr.LogSink) { + l.Info(level, msg, keysAndValues...) + }) +} + +// Error CompositeLogSink +func (c *compositeLogSink) Error(err error, msg string, keysAndValues ...interface{}) { + c.iter(func(l logr.LogSink) { + l.Error(err, msg, keysAndValues...) + }) +} + +// WithValue CompositeLogSink +func (c *compositeLogSink) WithValues(keysAndValues ...interface{}) logr.LogSink { + var logSinks = make([]logr.LogSink, len(c.logSinks)) + for i, l := range c.logSinks { + logSinks[i] = l.WithValues(keysAndValues...) + } + + return &compositeLogSink{ + logSinks: logSinks, + } +} + +// WithName CompositeLogSink +func (c *compositeLogSink) WithName(name string) logr.LogSink { + var logSinks = make([]logr.LogSink, len(c.logSinks)) + for i, l := range c.logSinks { + logSinks[i] = l.WithName(name) + } + + return &compositeLogSink{ + logSinks: logSinks, + } +} + +// NewCompositeLogger is the main entry-point to this implementation. +func NewCompositeLogger(logSinks []logr.LogSink) logr.Logger { + sink := &compositeLogSink{ + logSinks: logSinks, + } + return logr.New(sink) +} diff --git a/util/tele/corr_id.go b/util/tele/corr_id.go new file mode 100644 index 000000000..8720d9edb --- /dev/null +++ b/util/tele/corr_id.go @@ -0,0 +1,78 @@ +package tele + +import ( + "context" + + "github.com/go-logr/logr" + "github.com/google/uuid" +) + +// CorrIDKey is the type of the key used to store correlation +// IDs in context.Contexts. +type CorrIDKey string + +// CorrIDKeyVal is the key used to store the correlation ID in +// context.Contexts, HTTP headers, and other similar locations. +const CorrIDKeyVal CorrIDKey = "x-ms-correlation-request-id" + +// CorrID is a correlation ID that the cluster API provider +// sends with all API requests to Azure. Do not create one +// of these manually. Instead, use the CtxWithCorrelationID function +// to create one of these within a context.Context. +type CorrID string + +// ctxWithCorrID creates a CorrID and creates a new context.Context +// with the new CorrID in it. It returns the _new_ context and the +// newly created CorrID. If there was a problem creating the correlation +// ID, the new context will not have the correlation ID in it and the +// returned CorrID will be the empty string.After you call this function, prefer to +// use the newly created context over the old one. Common usage is +// below: +// +// ctx := context.Background() +// ctx, newCorrID := ctxWithCorrID(ctx) +// fmt.Println("new corr ID: ", newCorrID) +// doSomething(ctx) +func ctxWithCorrID(ctx context.Context) (context.Context, CorrID) { + if currentCorrIDIface := ctx.Value(CorrIDKeyVal); currentCorrIDIface != nil { + currentCorrID, ok := currentCorrIDIface.(CorrID) + if ok { + return ctx, currentCorrID + } + } + uid, err := uuid.NewRandom() + if err != nil { + return nil, CorrID("") + } + newCorrID := CorrID(uid.String()) + ctx = context.WithValue(ctx, CorrIDKeyVal, newCorrID) + return ctx, newCorrID +} + +// CorrIDFromCtx attempts to fetch a correlation ID from the given +// context.Context. If none exists, returns an empty CorrID and false. +// Otherwise returns the CorrID value and true. +func CorrIDFromCtx(ctx context.Context) (CorrID, bool) { + currentCorrIDIface := ctx.Value(CorrIDKeyVal) + if currentCorrIDIface == nil { + return CorrID(""), false + } + + if corrID, ok := currentCorrIDIface.(CorrID); ok { + return corrID, ok + } + + return CorrID(""), false +} + +// corrIDLogger attempts to fetch the correlation ID from the +// given ctx using CorrIDFromCtx. If it finds one, this function +// uses lggr.WithValues to return a new logr.Logger with the +// correlation ID in it. +func corrIDLogger(ctx context.Context, lggr logr.Logger) logr.Logger { + corrID, ok := CorrIDFromCtx(ctx) + if ok { + lggr = lggr.WithValues(string(CorrIDKeyVal), string(corrID)) + } + return lggr +} diff --git a/util/tele/span_logger.go b/util/tele/span_logger.go new file mode 100644 index 000000000..908d5283c --- /dev/null +++ b/util/tele/span_logger.go @@ -0,0 +1,172 @@ +package tele + +import ( + "context" + "fmt" + "time" + + "github.com/go-logr/logr" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" + "sigs.k8s.io/controller-runtime/pkg/log" +) + +// spanLogSink is a logr.LogSink implementation that writes log +// data to a span. +type spanLogSink struct { + trace.Span + name string + vals []interface{} +} + +// Init spanLogSink +func (*spanLogSink) Init(info logr.RuntimeInfo) { +} + +// End spanLogSink +func (s *spanLogSink) End(opts ...trace.SpanEndOption) { + s.Span.End(opts...) +} + +// Enabled spanLogSink +func (*spanLogSink) Enabled(v int) bool { + return true +} + +// key to attribute spanLogSink +func (s *spanLogSink) kvsToAttrs(keysAndValues ...interface{}) []attribute.KeyValue { + var ret []attribute.KeyValue + for i := 0; i < len(keysAndValues); i += 2 { + kv1 := fmt.Sprintf("%s", keysAndValues[i]) + kv2 := fmt.Sprintf("%s", keysAndValues[i+1]) + ret = append(ret, attribute.String(kv1, kv2)) + } + for i := 0; i < len(s.vals); i += 2 { + kv1 := fmt.Sprintf("%s", s.vals[i]) + kv2 := fmt.Sprintf("%s", s.vals[i+1]) + ret = append(ret, attribute.String(kv1, kv2)) + } + return ret +} + +// EventStr SpanLogSink +func (s *spanLogSink) evtStr(evtType, msg string) string { + return fmt.Sprintf( + "[%s | %s] %s", + evtType, + s.name, + msg, + ) +} + +// Info spanLogSink +func (s *spanLogSink) Info(level int, msg string, keysAndValues ...interface{}) { + attrs := s.kvsToAttrs(keysAndValues...) + s.AddEvent( + s.evtStr("INFO", msg), + trace.WithTimestamp(time.Now()), + trace.WithAttributes(attrs...), + ) +} + +// Error spanLogSink +func (s *spanLogSink) Error(err error, msg string, keysAndValues ...interface{}) { + attrs := s.kvsToAttrs(keysAndValues...) + s.AddEvent( + s.evtStr("ERROR", fmt.Sprintf("%s (%s)", msg, err)), + trace.WithTimestamp(time.Now()), + trace.WithAttributes(attrs...), + ) +} + +// WithValues spanLogSink +func (s *spanLogSink) WithValues(keysAndValues ...interface{}) logr.LogSink { + s.vals = append(s.vals, keysAndValues...) + return s +} + +// WithName spanLogSink +func (s *spanLogSink) WithName(name string) logr.LogSink { + s.name = name + return s +} + +// NewSpanLogSink is the main entry-point to this implementation. +func NewSpanLogSink(span trace.Span) logr.LogSink { + return &spanLogSink{ + Span: span, + } +} + +// Config holds optional, arbitrary configuration information +// to be added to logs and telemetry data. Instances of +// Config get passed to StartSpanWithLogger via the KVP function. +type Config struct { + KVPs map[string]string +} + +// tele key to values +func (c Config) teleKeyValues() []attribute.KeyValue { + ret := make([]attribute.KeyValue, len(c.KVPs)) + i := 0 + for k, v := range c.KVPs { + ret[i] = attribute.String(k, v) + i++ + } + return ret +} + +// Option is the modifier function used to configure +// StartSpanWithLogger. Generally speaking, you should +// not create your own option function. Instead, use +// built-in functions (like KVP) that create them. +type Option func(*Config) + +// KVP returns a new Option function that adds a the given +// key-value pair. +func KVP(key, value string) Option { + return func(cfg *Config) { + cfg.KVPs[key] = value + } +} + +// StartSpanWithLogger starts a new span with the global +// tracer returned from Tracer(), then returns a new logger +// implementation that composes both the logger from the +// given ctx and a logger that logs to the newly created span. +// +// Callers should make sure to call the function in the 3rd return +// value to ensure that the span is ended properly. In many cases, +// that can be done with a defer: +// +// ctx, lggr, done := StartSpanWithLogger(ctx, "my-span") +// defer done() +func StartSpanWithLogger( + ctx context.Context, + spanName string, + opts ...Option, +) (context.Context, logr.Logger, func()) { + cfg := &Config{KVPs: make(map[string]string)} + for _, opt := range opts { + opt(cfg) + } + ctx, span := Tracer().Start( + ctx, + spanName, + trace.WithAttributes(cfg.teleKeyValues()...), + ) + endFn := func() { + span.End() + } + + kvs := make([]interface{}, 0, 2*len(cfg.KVPs)) + for k, v := range cfg.KVPs { + kvs = append(kvs, k, v) + } + + lggr := log.FromContext(ctx, kvs...).WithName(spanName) + return ctx, NewCompositeLogger([]logr.LogSink{ + corrIDLogger(ctx, lggr).GetSink(), + NewSpanLogSink(span), + }), endFn +} diff --git a/util/tele/tele.go b/util/tele/tele.go new file mode 100644 index 000000000..f1422df78 --- /dev/null +++ b/util/tele/tele.go @@ -0,0 +1,38 @@ +package tele + +import ( + "context" + + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" +) + +type tracer struct { + trace.Tracer +} + +// Start tracer +func (t tracer) Start( + ctx context.Context, + op string, + opts ...trace.SpanStartOption, +) (context.Context, trace.Span) { + ctx, corrID := ctxWithCorrID(ctx) + opts = append( + opts, + trace.WithSpanKind(trace.SpanKindClient), + trace.WithAttributes(attribute.String( + string(CorrIDKeyVal), + string(corrID), + )), + ) + return t.Tracer.Start(ctx, op, opts...) +} + +// Return tracer +func Tracer() trace.Tracer { + return tracer{ + Tracer: otel.Tracer("capo"), + } +} diff --git a/util/tracing/tracing.go b/util/tracing/tracing.go new file mode 100644 index 000000000..bec2b8f67 --- /dev/null +++ b/util/tracing/tracing.go @@ -0,0 +1,53 @@ +package tracing + +import ( + "context" + "net/http" +) + +// Tracer represents an HTTP tracing facility. +type Tracer interface { + NewTransport(base *http.Transport) http.RoundTripper + StartSpan(ctx context.Context, name string) context.Context + EndSpan(ctx context.Context, httpStatusCode int, err error) +} + +var ( + tracer Tracer +) + +// Register will register the provided Tracer. +func Register(t Tracer) { + tracer = t +} + +// IsEnabled returns true if a Tracer has been registered. +func IsEnabled() bool { + return tracer != nil +} + +// NewTransport creates a new instrumenting http.RoundTripper for the +// registered Tracer. If no Tracer has been registered it returns nil. +func NewTransport(base *http.Transport) http.RoundTripper { + if tracer != nil { + return tracer.NewTransport(base) + } + return nil +} + +// StartSpan starts a trace span with the specified name, associating it with the +// provided context. Has no effect if a Tracer has not been registered. +func StartSpan(ctx context.Context, name string) context.Context { + if tracer != nil { + return tracer.StartSpan(ctx, name) + } + return ctx +} + +// EndSpan ends a previously started span stored in the context. +// Has no effect if a Tracer has not been registered. +func EndSpan(ctx context.Context, httpStatusCode int, err error) { + if tracer != nil { + tracer.EndSpan(ctx, httpStatusCode, err) + } +} From 86b7eab10272d9d8f5de1361519425dc453a4c14 Mon Sep 17 00:00:00 2001 From: outscale-vbr Date: Tue, 11 Oct 2022 18:29:11 +0000 Subject: [PATCH 2/2] Optional opentracing with docs and boilerplate --- cloud/opentracing/metrics.go | 16 ++++ cloud/opentracing/opentelemetry.go | 16 ++++ cloud/opentracing/traces.go | 16 ++++ controllers/osccluster_controller.go | 73 +++---------------- .../osccluster_internetservice_controller.go | 14 ++++ .../osccluster_loadbalancer_controller.go | 15 +++- .../osccluster_natservice_controller.go | 12 +++ controllers/osccluster_net_controller.go | 11 ++- controllers/osccluster_publicip_controller.go | 10 +++ .../osccluster_routetable_controller.go | 32 +++++++- .../osccluster_securitygroup_controller.go | 17 +++++ controllers/osccluster_subnet_controller.go | 12 +++ controllers/oscmachine_controller.go | 36 --------- controllers/oscmachine_image_controller.go | 8 +- controllers/oscmachine_keypair_controller.go | 10 ++- controllers/oscmachine_vm_controller.go | 40 ++++++++++ controllers/oscmachine_volume_controller.go | 16 +++- docs/src/SUMMARY.md | 1 + docs/src/topics/tracing.md | 10 +++ docs/src/topics/troubleshooting.md | 47 ++++++++++++ main.go | 21 +++--- util/tele/composite_logger.go | 16 ++++ util/tele/corr_id.go | 16 ++++ util/tele/span_logger.go | 16 ++++ util/tele/tele.go | 16 ++++ util/tracing/tracing.go | 16 ++++ 26 files changed, 397 insertions(+), 116 deletions(-) create mode 100644 docs/src/topics/tracing.md diff --git a/cloud/opentracing/metrics.go b/cloud/opentracing/metrics.go index aef1f8a95..8059df583 100644 --- a/cloud/opentracing/metrics.go +++ b/cloud/opentracing/metrics.go @@ -1,3 +1,19 @@ +/* +Copyright 2022 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + package opentracing import ( diff --git a/cloud/opentracing/opentelemetry.go b/cloud/opentracing/opentelemetry.go index ab19060ec..979b1246f 100644 --- a/cloud/opentracing/opentelemetry.go +++ b/cloud/opentracing/opentelemetry.go @@ -1,3 +1,19 @@ +/* +Copyright 2022 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + package opentracing import ( diff --git a/cloud/opentracing/traces.go b/cloud/opentracing/traces.go index 31e737b52..0e781e378 100644 --- a/cloud/opentracing/traces.go +++ b/cloud/opentracing/traces.go @@ -1,3 +1,19 @@ +/* +Copyright 2022 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + package opentracing import ( diff --git a/controllers/osccluster_controller.go b/controllers/osccluster_controller.go index 6705d6628..c85b8e26f 100644 --- a/controllers/osccluster_controller.go +++ b/controllers/osccluster_controller.go @@ -103,7 +103,7 @@ func (r *OscClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) ctx, _, reconcileDone := tele.StartSpanWithLogger( ctx, - "controllers.OscClusterReconciler.Reconcile", + "controllers.OscClusterReconciler.reconcile", tele.KVP("namespace", req.Namespace), tele.KVP("name", req.Name), tele.KVP("kind", "OscCluster"), @@ -301,92 +301,66 @@ func (r *OscClusterReconciler) reconcile(ctx context.Context, clusterScope *scop clusterScope.Info("Set OscCluster status to not ready") clusterScope.SetNotReady() // Reconcile each element of the cluster - ctx, _, netDone := tele.StartSpanWithLogger(ctx, "controllers.OscClusterControllers.netReconcile") netSvc := r.getNetSvc(ctx, *clusterScope) reconcileNet, err := reconcileNet(ctx, clusterScope, netSvc) if err != nil { clusterScope.Error(err, "failed to reconcile net") conditions.MarkFalse(osccluster, infrastructurev1beta1.NetReadyCondition, infrastructurev1beta1.NetReconciliationFailedReason, clusterv1.ConditionSeverityWarning, err.Error()) - netDone() return reconcileNet, err } - netDone() conditions.MarkTrue(osccluster, infrastructurev1beta1.NetReadyCondition) - ctx, _, subnetDone := tele.StartSpanWithLogger(ctx, "controllers.OscClusterControllers.subnetReconcile") - subnetSvc := r.getSubnetSvc(ctx, *clusterScope) reconcileSubnets, err := reconcileSubnet(ctx, clusterScope, subnetSvc) if err != nil { clusterScope.Error(err, "failed to reconcile subnet") conditions.MarkFalse(osccluster, infrastructurev1beta1.SubnetsReadyCondition, infrastructurev1beta1.SubnetsReconciliationFailedReason, clusterv1.ConditionSeverityWarning, err.Error()) - subnetDone() return reconcileSubnets, err } - subnetDone() conditions.MarkTrue(osccluster, infrastructurev1beta1.SubnetsReadyCondition) - ctx, _, internetServiceDone := tele.StartSpanWithLogger(ctx, "controllers.OscClusterControllers.internetServiceReconcile") - internetServiceSvc := r.getInternetServiceSvc(ctx, *clusterScope) reconcileInternetService, err := reconcileInternetService(ctx, clusterScope, internetServiceSvc) if err != nil { clusterScope.Error(err, "failed to reconcile internetService") conditions.MarkFalse(osccluster, infrastructurev1beta1.InternetServicesReadyCondition, infrastructurev1beta1.InternetServicesFailedReason, clusterv1.ConditionSeverityWarning, err.Error()) - internetServiceDone() return reconcileInternetService, err } - internetServiceDone() conditions.MarkTrue(osccluster, infrastructurev1beta1.InternetServicesReadyCondition) - ctx, _, publicIpDone := tele.StartSpanWithLogger(ctx, "controllers.OscClusterControllers.publicIpReconcile") - publicIpSvc := r.getPublicIpSvc(ctx, *clusterScope) reconcilePublicIp, err := reconcilePublicIp(ctx, clusterScope, publicIpSvc) if err != nil { clusterScope.Error(err, "failed to reconcile publicIp") conditions.MarkFalse(osccluster, infrastructurev1beta1.PublicIpsReadyCondition, infrastructurev1beta1.PublicIpsFailedReason, clusterv1.ConditionSeverityWarning, err.Error()) - publicIpDone() return reconcilePublicIp, err } - publicIpDone() conditions.MarkTrue(osccluster, infrastructurev1beta1.PublicIpsReadyCondition) - ctx, _, securityGroupDone := tele.StartSpanWithLogger(ctx, "controllers.OscClusterControllers.securityGroupReconcile") - securityGroupSvc := r.getSecurityGroupSvc(ctx, *clusterScope) reconcileSecurityGroups, err := reconcileSecurityGroup(ctx, clusterScope, securityGroupSvc) if err != nil { clusterScope.Error(err, "failed to reconcile securityGroup") conditions.MarkFalse(osccluster, infrastructurev1beta1.SecurityGroupReadyCondition, infrastructurev1beta1.SecurityGroupReconciliationFailedReason, clusterv1.ConditionSeverityWarning, err.Error()) - securityGroupDone() return reconcileSecurityGroups, err } - securityGroupDone() conditions.MarkTrue(osccluster, infrastructurev1beta1.SecurityGroupReadyCondition) - ctx, _, routeTableDone := tele.StartSpanWithLogger(ctx, "controller.OscClusterControllers.routeTableReconcile") - routeTableSvc := r.getRouteTableSvc(ctx, *clusterScope) reconcileRouteTables, err := reconcileRouteTable(ctx, clusterScope, routeTableSvc) if err != nil { clusterScope.Error(err, "failed to reconcile routeTable") conditions.MarkFalse(osccluster, infrastructurev1beta1.RouteTablesReadyCondition, infrastructurev1beta1.RouteTableReconciliationFailedReason, clusterv1.ConditionSeverityWarning, err.Error()) - routeTableDone() return reconcileRouteTables, err } - routeTableDone() conditions.MarkTrue(osccluster, infrastructurev1beta1.RouteTablesReadyCondition) - ctx, _, natServiceDone := tele.StartSpanWithLogger(ctx, "controller.OscClusterControllers.natServiceReconcile") - natServiceSvc := r.getNatServiceSvc(ctx, *clusterScope) reconcileNatService, err := reconcileNatService(ctx, clusterScope, natServiceSvc) if err != nil { clusterScope.Error(err, "failed to reconcile natservice") conditions.MarkFalse(osccluster, infrastructurev1beta1.NatServicesReadyCondition, infrastructurev1beta1.NatServicesReconciliationFailedReason, clusterv1.ConditionSeverityWarning, err.Error()) - natServiceDone() return reconcileNatService, nil } conditions.MarkTrue(osccluster, infrastructurev1beta1.NatServicesReadyCondition) @@ -395,17 +369,12 @@ func (r *OscClusterReconciler) reconcile(ctx context.Context, clusterScope *scop if err != nil { clusterScope.Error(err, "failed to reconcile NatRouteTable") conditions.MarkFalse(osccluster, infrastructurev1beta1.RouteTablesReadyCondition, infrastructurev1beta1.RouteTableReconciliationFailedReason, clusterv1.ConditionSeverityWarning, err.Error()) - natServiceDone() return reconcileNatRouteTable, err } - natServiceDone() conditions.MarkTrue(osccluster, infrastructurev1beta1.RouteTablesReadyCondition) - ctx, _, loadBalancerDone := tele.StartSpanWithLogger(ctx, "controllers.OscClusterControllers.loadBalancerReconcile") - loadBalancerSvc := r.getLoadBalancerSvc(ctx, *clusterScope) _, err = reconcileLoadBalancer(ctx, clusterScope, loadBalancerSvc) - loadBalancerDone() clusterScope.Info("Set OscCluster status to ready") clusterScope.SetReady() return reconcile.Result{}, nil @@ -418,6 +387,15 @@ func (r *OscClusterReconciler) reconcileDelete(ctx context.Context, clusterScope // reconcile deletion of each element of the cluster + ctx, _, reconcileDone := tele.StartSpanWithLogger( + ctx, + "controllers.OscClusterReconciler.reconcileDelete", + tele.KVP("namespace", clusterScope.GetNamespace()), + tele.KVP("name", clusterScope.GetName()), + tele.KVP("kind", "OscCluster"), + ) + defer reconcileDone() + machines, _, err := clusterScope.ListMachines(ctx) if err != nil { return reconcile.Result{}, fmt.Errorf("failed to list machines for OscCluster %s/%s: %+v", err, clusterScope.GetNamespace(), clusterScope.GetName()) @@ -432,84 +410,53 @@ func (r *OscClusterReconciler) reconcileDelete(ctx context.Context, clusterScope return reconcile.Result{RequeueAfter: 10 * time.Second}, nil } - ctx, _, loadBalancerDone := tele.StartSpanWithLogger(ctx, "controllers.OscMachineReconciler.reconcileLoadBalancerDelete") - loadBalancerSvc := r.getLoadBalancerSvc(ctx, *clusterScope) reconcileDeleteLoadBalancer, err := reconcileDeleteLoadBalancer(ctx, clusterScope, loadBalancerSvc) if err != nil { - loadBalancerDone() return reconcileDeleteLoadBalancer, err } - loadBalancerDone() - - ctx, _, natServiceDone := tele.StartSpanWithLogger(ctx, "controllers.OscMachineReconciler.reconcileNatServiceDelete") natServiceSvc := r.getNatServiceSvc(ctx, *clusterScope) reconcileDeleteNatService, err := reconcileDeleteNatService(ctx, clusterScope, natServiceSvc) if err != nil { - natServiceDone() return reconcileDeleteNatService, err } - natServiceDone() - ctx, _, publicIpDone := tele.StartSpanWithLogger(ctx, "controllers.OscMachineReconciler.reconcilePublicIpDelete") publicIpSvc := r.getPublicIpSvc(ctx, *clusterScope) reconcileDeletePublicIp, err := reconcileDeletePublicIp(ctx, clusterScope, publicIpSvc) if err != nil { - publicIpDone() return reconcileDeletePublicIp, err } - publicIpDone() - - ctx, _, routeTableDone := tele.StartSpanWithLogger(ctx, "controllers.OscMachineReconciler.reconcileRouteTableDelete") routeTableSvc := r.getRouteTableSvc(ctx, *clusterScope) reconcileDeleteRouteTable, err := reconcileDeleteRouteTable(ctx, clusterScope, routeTableSvc) if err != nil { - routeTableDone() return reconcileDeleteRouteTable, err } - routeTableDone() - - ctx, _, securityGroupDone := tele.StartSpanWithLogger(ctx, "controllers.OscMachineReconciler.reconcileSecurityGroupDelete") securityGroupSvc := r.getSecurityGroupSvc(ctx, *clusterScope) reconcileDeleteSecurityGroup, err := reconcileDeleteSecurityGroup(ctx, clusterScope, securityGroupSvc) if err != nil { - securityGroupDone() return reconcileDeleteSecurityGroup, err } - securityGroupDone() - - ctx, _, internetServiceGroupDone := tele.StartSpanWithLogger(ctx, "controllers.OscMachineReconciler.reconcileInternetServiceGroupDelete") internetServiceSvc := r.getInternetServiceSvc(ctx, *clusterScope) reconcileDeleteInternetService, err := reconcileDeleteInternetService(ctx, clusterScope, internetServiceSvc) if err != nil { - internetServiceGroupDone() return reconcileDeleteInternetService, err } - internetServiceGroupDone() - - ctx, _, subnetDone := tele.StartSpanWithLogger(ctx, "controllers.OscMachineReconciler.reconcileSubnetDelete") subnetSvc := r.getSubnetSvc(ctx, *clusterScope) reconcileDeleteSubnet, err := reconcileDeleteSubnet(ctx, clusterScope, subnetSvc) if err != nil { - subnetDone() return reconcileDeleteSubnet, err } - subnetDone() - - ctx, _, netDone := tele.StartSpanWithLogger(ctx, "controllers.OscMachineReconciler.reconcileNetDelete") netSvc := r.getNetSvc(ctx, *clusterScope) reconcileDeleteNet, err := reconcileDeleteNet(ctx, clusterScope, netSvc) if err != nil { - netDone() return reconcileDeleteNet, err } - netDone() controllerutil.RemoveFinalizer(osccluster, "oscclusters.infrastructure.cluster.x-k8s.io") return reconcile.Result{}, nil diff --git a/controllers/osccluster_internetservice_controller.go b/controllers/osccluster_internetservice_controller.go index ab58b16b1..039cd900b 100644 --- a/controllers/osccluster_internetservice_controller.go +++ b/controllers/osccluster_internetservice_controller.go @@ -21,6 +21,7 @@ import ( "github.com/outscale-dev/cluster-api-provider-outscale.git/cloud/scope" "github.com/outscale-dev/cluster-api-provider-outscale.git/cloud/services/net" tag "github.com/outscale-dev/cluster-api-provider-outscale.git/cloud/tag" + "github.com/outscale-dev/cluster-api-provider-outscale.git/util/tele" osc "github.com/outscale/osc-sdk-go/v2" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" "sigs.k8s.io/controller-runtime/pkg/reconcile" @@ -60,7 +61,9 @@ func reconcileInternetService(ctx context.Context, clusterScope *scope.ClusterSc netSpec.SetDefaultValue() netName := netSpec.Name + "-" + clusterScope.GetUID() netId, err := getNetResourceId(netName, clusterScope) + ctx, _, internetServiceDone := tele.StartSpanWithLogger(ctx, "controllers.OscClusterControllers.reconcileInternetService") if err != nil { + internetServiceDone() return reconcile.Result{}, err } if len(internetServiceRef.ResourceMap) == 0 { @@ -73,6 +76,7 @@ func reconcileInternetService(ctx context.Context, clusterScope *scope.ClusterSc clusterScope.Info("### Get internetServiceId ###", "internetservice", internetServiceRef.ResourceMap) internetService, err = internetServiceSvc.GetInternetService(internetServiceId) if err != nil { + internetServiceDone() return reconcile.Result{}, err } } @@ -80,11 +84,13 @@ func reconcileInternetService(ctx context.Context, clusterScope *scope.ClusterSc clusterScope.Info("Create the desired internetservice", "internetServiceName", internetServiceName) internetService, err := internetServiceSvc.CreateInternetService(internetServiceName) if err != nil { + internetServiceDone() return reconcile.Result{}, fmt.Errorf("%w Can not create internetservice for Osccluster %s/%s", err, clusterScope.GetNamespace(), clusterScope.GetName()) } clusterScope.Info("Link the desired internetservice with a net", "internetServiceName", internetServiceName) err = internetServiceSvc.LinkInternetService(*internetService.InternetServiceId, netId) if err != nil { + internetServiceDone() return reconcile.Result{}, fmt.Errorf("%w Can not link internetService with net for Osccluster %s/%s", err, clusterScope.GetNamespace(), clusterScope.GetName()) } clusterScope.Info("### Get internetService ###", "internetservice", internetService) @@ -92,6 +98,7 @@ func reconcileInternetService(ctx context.Context, clusterScope *scope.ClusterSc internetServiceSpec.ResourceId = internetService.GetInternetServiceId() } + internetServiceDone() return reconcile.Result{}, nil } @@ -108,8 +115,10 @@ func reconcileDeleteInternetService(ctx context.Context, clusterScope *scope.Clu netSpec.SetDefaultValue() netName := netSpec.Name + "-" + clusterScope.GetUID() + ctx, _, internetServiceDone := tele.StartSpanWithLogger(ctx, "controllers.OscClusterReconciler.reconcileDeleteInternetService") netId, err := getNetResourceId(netName, clusterScope) if err != nil { + internetServiceDone() return reconcile.Result{}, err } @@ -117,23 +126,28 @@ func reconcileDeleteInternetService(ctx context.Context, clusterScope *scope.Clu internetServiceName := internetServiceSpec.Name internetService, err := internetServiceSvc.GetInternetService(internetServiceId) if err != nil { + internetServiceDone() return reconcile.Result{}, err } if internetService == nil { clusterScope.Info("the desired internetservice does not exist anymore", "internetServiceName", internetServiceName) controllerutil.RemoveFinalizer(osccluster, "oscclusters.infrastructure.cluster.x-k8s.io") + internetServiceDone() return reconcile.Result{}, nil } err = internetServiceSvc.UnlinkInternetService(internetServiceId, netId) clusterScope.Info("Unlink the desired internetservice", "internetServiceName", internetServiceName) if err != nil { + internetServiceDone() return reconcile.Result{}, fmt.Errorf("%w Can not unlink internetService and net for Osccluster %s/%s", err, clusterScope.GetNamespace(), clusterScope.GetName()) } err = internetServiceSvc.DeleteInternetService(internetServiceId) clusterScope.Info("Delete the desired internetservice", "internetServiceName", internetServiceName) if err != nil { + internetServiceDone() return reconcile.Result{}, fmt.Errorf("%w Can not delete internetService for Osccluster %s/%s", err, clusterScope.GetNamespace(), clusterScope.GetName()) } + internetServiceDone() return reconcile.Result{}, nil } diff --git a/controllers/osccluster_loadbalancer_controller.go b/controllers/osccluster_loadbalancer_controller.go index 427b71d21..9fc3472c2 100644 --- a/controllers/osccluster_loadbalancer_controller.go +++ b/controllers/osccluster_loadbalancer_controller.go @@ -23,6 +23,7 @@ import ( "github.com/outscale-dev/cluster-api-provider-outscale.git/cloud/scope" "github.com/outscale-dev/cluster-api-provider-outscale.git/cloud/services/service" + "github.com/outscale-dev/cluster-api-provider-outscale.git/util/tele" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" "sigs.k8s.io/controller-runtime/pkg/reconcile" @@ -154,18 +155,22 @@ func reconcileLoadBalancer(ctx context.Context, clusterScope *scope.ClusterScope loadBalancerSpec := clusterScope.GetLoadBalancer() loadBalancerName := loadBalancerSpec.LoadBalancerName clusterScope.Info("Check if the desired loadbalancer exist", "loadBalancerName", loadBalancerName) + ctx, _, loadBalancerDone := tele.StartSpanWithLogger(ctx, "controllers.OscClusterControllers.reconcileLoadBalancer") loadbalancer, err := loadBalancerSvc.GetLoadBalancer(loadBalancerSpec) if err != nil { + loadBalancerDone() return reconcile.Result{}, err } subnetName := loadBalancerSpec.SubnetName + "-" + clusterScope.GetUID() subnetId, err := getSubnetResourceId(subnetName, clusterScope) if err != nil { + loadBalancerDone() return reconcile.Result{}, err } securityGroupName := loadBalancerSpec.SecurityGroupName + "-" + clusterScope.GetUID() securityGroupId, err := getSecurityGroupResourceId(securityGroupName, clusterScope) if err != nil { + loadBalancerDone() return reconcile.Result{}, err } if loadbalancer == nil { @@ -174,11 +179,13 @@ func reconcileLoadBalancer(ctx context.Context, clusterScope *scope.ClusterScope clusterScope.Info("Create the desired loadBalancer", "loadBalancerName", loadBalancerName) _, err := loadBalancerSvc.CreateLoadBalancer(loadBalancerSpec, subnetId, securityGroupId) if err != nil { + loadBalancerDone() return reconcile.Result{}, fmt.Errorf("%w Can not create loadBalancer for Osccluster %s/%s", err, clusterScope.GetNamespace(), clusterScope.GetName()) } clusterScope.Info("Configure the desired loadBalancer", "loadBalancerName", loadBalancerName) loadbalancer, err = loadBalancerSvc.ConfigureHealthCheck(loadBalancerSpec) if err != nil { + loadBalancerDone() return reconcile.Result{}, fmt.Errorf("%w Can not configure healthcheck for Osccluster %s/%s", err, clusterScope.GetNamespace(), clusterScope.GetName()) } clusterScope.Info("### Get lb ###", "loadbalancer", loadbalancer) @@ -193,6 +200,7 @@ func reconcileLoadBalancer(ctx context.Context, clusterScope *scope.ClusterScope Host: controlPlaneEndpoint, Port: controlPlanePort, }) + loadBalancerDone() return reconcile.Result{}, nil } @@ -206,25 +214,30 @@ func reconcileDeleteLoadBalancer(ctx context.Context, clusterScope *scope.Cluste loadBalancerSpec := clusterScope.GetLoadBalancer() loadBalancerSpec.SetDefaultValue() loadBalancerName := loadBalancerSpec.LoadBalancerName - + ctx, _, loadBalancerDone := tele.StartSpanWithLogger(ctx, "controllers.OscClusterReconciler.reconcileDeleteLoadBalancer") loadbalancer, err := loadBalancerSvc.GetLoadBalancer(loadBalancerSpec) if err != nil { + loadBalancerDone() return reconcile.Result{}, err } if loadbalancer == nil { clusterScope.Info("the desired loadBalancer does not exist anymore", "loadBalancerName", loadBalancerName) controllerutil.RemoveFinalizer(osccluster, "oscclusters.infrastructure.cluster.x-k8s.io") + loadBalancerDone() return reconcile.Result{}, nil } err = loadBalancerSvc.CheckLoadBalancerDeregisterVm(5, 120, loadBalancerSpec) if err != nil { + loadBalancerDone() return reconcile.Result{}, fmt.Errorf("%w VmBackend is not deregister in loadBalancer %s for OscCluster %s/%s", err, loadBalancerSpec.LoadBalancerName, clusterScope.GetNamespace(), clusterScope.GetName()) } err = loadBalancerSvc.DeleteLoadBalancer(loadBalancerSpec) if err != nil { clusterScope.Info("Delete the desired loadBalancer", "loadBalancerName", loadBalancerName) + loadBalancerDone() return reconcile.Result{}, fmt.Errorf("%w Can not delete loadBalancer for Osccluster %s/%s", err, clusterScope.GetNamespace(), clusterScope.GetName()) } + loadBalancerDone() return reconcile.Result{}, nil } diff --git a/controllers/osccluster_natservice_controller.go b/controllers/osccluster_natservice_controller.go index c995d5e93..ef52fbf34 100644 --- a/controllers/osccluster_natservice_controller.go +++ b/controllers/osccluster_natservice_controller.go @@ -23,6 +23,7 @@ import ( "github.com/outscale-dev/cluster-api-provider-outscale.git/cloud/scope" "github.com/outscale-dev/cluster-api-provider-outscale.git/cloud/services/net" tag "github.com/outscale-dev/cluster-api-provider-outscale.git/cloud/tag" + "github.com/outscale-dev/cluster-api-provider-outscale.git/util/tele" osc "github.com/outscale/osc-sdk-go/v2" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" "sigs.k8s.io/controller-runtime/pkg/reconcile" @@ -91,7 +92,9 @@ func reconcileNatService(ctx context.Context, clusterScope *scope.ClusterScope, var natService *osc.NatService publicIpName := natServiceSpec.PublicIpName + "-" + clusterScope.GetUID() publicIpId, err := getPublicIpResourceId(publicIpName, clusterScope) + ctx, _, natServiceDone := tele.StartSpanWithLogger(ctx, "controller.OscClusterControllers.reconcileNatService") if err != nil { + natServiceDone() return reconcile.Result{}, err } @@ -99,6 +102,7 @@ func reconcileNatService(ctx context.Context, clusterScope *scope.ClusterScope, subnetId, err := getSubnetResourceId(subnetName, clusterScope) if err != nil { + natServiceDone() return reconcile.Result{}, err } if len(natServiceRef.ResourceMap) == 0 { @@ -111,6 +115,7 @@ func reconcileNatService(ctx context.Context, clusterScope *scope.ClusterScope, clusterScope.Info("### Get natService Id ###", "natService", natServiceRef.ResourceMap) natService, err = natServiceSvc.GetNatService(natServiceId) if err != nil { + natServiceDone() return reconcile.Result{}, err } } @@ -119,12 +124,14 @@ func reconcileNatService(ctx context.Context, clusterScope *scope.ClusterScope, clusterScope.Info("Create the desired natService", "natServiceName", natServiceName) natService, err := natServiceSvc.CreateNatService(publicIpId, subnetId, natServiceName) if err != nil { + natServiceDone() return reconcile.Result{}, fmt.Errorf("%w Can not create natService for Osccluster %s/%s", err, clusterScope.GetNamespace(), clusterScope.GetName()) } clusterScope.Info("### Get natService ###", "natService", natService) natServiceRef.ResourceMap[natServiceName] = natService.GetNatServiceId() natServiceSpec.ResourceId = natService.GetNatServiceId() } + natServiceDone() return reconcile.Result{}, nil } @@ -138,19 +145,24 @@ func reconcileDeleteNatService(ctx context.Context, clusterScope *scope.ClusterS natServiceName := natServiceSpec.Name + "-" + clusterScope.GetUID() natServiceId := natServiceSpec.ResourceId + ctx, _, natServiceDone := tele.StartSpanWithLogger(ctx, "controllers.OscClusterReconciler.reconcileDeleteNatService") natService, err := natServiceSvc.GetNatService(natServiceId) if err != nil { + natServiceDone() return reconcile.Result{}, err } if natService == nil { clusterScope.Info("the desired natService does not exist anymore", "natServiceName", natServiceName) controllerutil.RemoveFinalizer(osccluster, "oscclusters.infrastructure.cluster.x-k8s.io") + natServiceDone() return reconcile.Result{}, nil } err = natServiceSvc.DeleteNatService(natServiceId) if err != nil { clusterScope.Info("Delete the desired natService", "natServiceName", natServiceName) + natServiceDone() return reconcile.Result{}, fmt.Errorf("%w Can not delete natService for Osccluster %s/%s", err, clusterScope.GetNamespace(), clusterScope.GetName()) } + natServiceDone() return reconcile.Result{}, err } diff --git a/controllers/osccluster_net_controller.go b/controllers/osccluster_net_controller.go index c85597791..7a763982b 100644 --- a/controllers/osccluster_net_controller.go +++ b/controllers/osccluster_net_controller.go @@ -24,6 +24,7 @@ import ( "github.com/outscale-dev/cluster-api-provider-outscale.git/cloud/scope" "github.com/outscale-dev/cluster-api-provider-outscale.git/cloud/services/net" tag "github.com/outscale-dev/cluster-api-provider-outscale.git/cloud/tag" + "github.com/outscale-dev/cluster-api-provider-outscale.git/util/tele" osc "github.com/outscale/osc-sdk-go/v2" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" "sigs.k8s.io/controller-runtime/pkg/reconcile" @@ -71,6 +72,7 @@ func reconcileNet(ctx context.Context, clusterScope *scope.ClusterScope, netSvc if len(netRef.ResourceMap) == 0 { netRef.ResourceMap = make(map[string]string) } + ctx, _, netDone := tele.StartSpanWithLogger(ctx, "controllers.OscClusterControllers.reconcileNet") if netSpec.ResourceId != "" { netRef.ResourceMap[netName] = netSpec.ResourceId netId := netSpec.ResourceId @@ -78,6 +80,7 @@ func reconcileNet(ctx context.Context, clusterScope *scope.ClusterScope, netSvc clusterScope.Info("### Get netId ###", "net", netRef.ResourceMap) net, err = netSvc.GetNet(netId) if err != nil { + netDone() return reconcile.Result{}, err } @@ -86,6 +89,7 @@ func reconcileNet(ctx context.Context, clusterScope *scope.ClusterScope, netSvc clusterScope.Info("Create the desired net", "netName", netName) net, err := netSvc.CreateNet(netSpec, clusterName, netName) if err != nil { + netDone() return reconcile.Result{}, fmt.Errorf("%w Can not create net for Osccluster %s/%s", err, clusterScope.GetNamespace(), clusterScope.GetName()) } clusterScope.Info("### Get net ###", "net", net) @@ -94,6 +98,7 @@ func reconcileNet(ctx context.Context, clusterScope *scope.ClusterScope, netSvc netRef.ResourceMap[netName] = net.GetNetId() netSpec.ResourceId = net.GetNetId() } + netDone() return reconcile.Result{}, nil } @@ -105,21 +110,25 @@ func reconcileDeleteNet(ctx context.Context, clusterScope *scope.ClusterScope, n netSpec.SetDefaultValue() netId := netSpec.ResourceId netName := netSpec.Name + "-" + clusterScope.GetUID() - + ctx, _, netDone := tele.StartSpanWithLogger(ctx, "controllers.OscClusterReconciler.reconcileDeleteNet") clusterScope.Info("Delete net") net, err := netSvc.GetNet(netId) if err != nil { + netDone() return reconcile.Result{}, err } if net == nil { clusterScope.Info("The desired net does not exist anymore", "netName", netName) controllerutil.RemoveFinalizer(osccluster, "oscclusters.infrastructure.cluster.x-k8s.io") + netDone() return reconcile.Result{}, nil } err = netSvc.DeleteNet(netId) if err != nil { clusterScope.Info("Delete the desired net", "netName", netName) + netDone() return reconcile.Result{}, fmt.Errorf("%w Can not delete net for Osccluster %s/%s", err, clusterScope.GetNamespace(), clusterScope.GetName()) } + netDone() return reconcile.Result{}, nil } diff --git a/controllers/osccluster_publicip_controller.go b/controllers/osccluster_publicip_controller.go index 16ee93cd0..d388a5eb2 100644 --- a/controllers/osccluster_publicip_controller.go +++ b/controllers/osccluster_publicip_controller.go @@ -24,6 +24,7 @@ import ( "github.com/outscale-dev/cluster-api-provider-outscale.git/cloud/scope" "github.com/outscale-dev/cluster-api-provider-outscale.git/cloud/services/security" tag "github.com/outscale-dev/cluster-api-provider-outscale.git/cloud/tag" + "github.com/outscale-dev/cluster-api-provider-outscale.git/util/tele" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" "sigs.k8s.io/controller-runtime/pkg/reconcile" ) @@ -120,8 +121,10 @@ func reconcilePublicIp(ctx context.Context, clusterScope *scope.ClusterScope, pu publicIpIds = append(publicIpIds, publicIpId) } clusterScope.Info("Check if the desired publicip exist") + ctx, _, publicIpDone := tele.StartSpanWithLogger(ctx, "controllers.OscClusterControllers.reconcilePublicIp") validPublicIpIds, err := publicIpSvc.ValidatePublicIpIds(publicIpIds) if err != nil { + publicIpDone() return reconcile.Result{}, err } clusterScope.Info("### Check Id ###", "publicip", publicIpIds) @@ -143,6 +146,7 @@ func reconcilePublicIp(ctx context.Context, clusterScope *scope.ClusterScope, pu if !Contains(validPublicIpIds, publicIpId) { publicIp, err := publicIpSvc.CreatePublicIp(publicIpName) if err != nil { + publicIpDone() return reconcile.Result{}, fmt.Errorf("%w Can not create publicIp for Osccluster %s/%s", err, clusterScope.GetNamespace(), clusterScope.GetName()) } clusterScope.Info("### Get publicIp ###", "publicip", publicIp) @@ -150,6 +154,7 @@ func reconcilePublicIp(ctx context.Context, clusterScope *scope.ClusterScope, pu publicIpSpec.ResourceId = publicIp.GetPublicIpId() } } + publicIpDone() return reconcile.Result{}, nil } @@ -176,6 +181,7 @@ func reconcileDeletePublicIp(ctx context.Context, clusterScope *scope.ClusterSco if err != nil { return reconcile.Result{}, err } + ctx, _, publicIpDone := tele.StartSpanWithLogger(ctx, "controllers.OscClusterReconciler.reconcileDeletePublicIp") clusterScope.Info("### Check Id ###", "publicip", publicIpIds) for _, publicIpSpec := range publicIpsSpec { publicIpId := publicIpSpec.ResourceId @@ -184,10 +190,12 @@ func reconcileDeletePublicIp(ctx context.Context, clusterScope *scope.ClusterSco clusterScope.Info("### Check validPublicIpIds###", "validPublicIpIds", validPublicIpIds) if !Contains(validPublicIpIds, publicIpId) { controllerutil.RemoveFinalizer(osccluster, "oscclusters.infrastructure.cluster.x-k8s.io") + publicIpDone() return reconcile.Result{}, nil } err = publicIpSvc.CheckPublicIpUnlink(5, 120, publicIpId) if err != nil { + publicIpDone() return reconcile.Result{}, fmt.Errorf("%w Can not delete publicIp %s for Osccluster %s/%s", err, publicIpId, clusterScope.GetNamespace(), clusterScope.GetName()) } @@ -195,9 +203,11 @@ func reconcileDeletePublicIp(ctx context.Context, clusterScope *scope.ClusterSco clusterScope.Info("Delete the desired publicip", "publicIpName", publicIpName) err = publicIpSvc.DeletePublicIp(publicIpId) if err != nil { + publicIpDone() return reconcile.Result{}, fmt.Errorf("%w Can not delete publicIp for Osccluster %s/%s", err, clusterScope.GetNamespace(), clusterScope.GetName()) } } + publicIpDone() return reconcile.Result{}, nil } diff --git a/controllers/osccluster_routetable_controller.go b/controllers/osccluster_routetable_controller.go index bedbc1692..acc849d02 100644 --- a/controllers/osccluster_routetable_controller.go +++ b/controllers/osccluster_routetable_controller.go @@ -24,6 +24,7 @@ import ( "github.com/outscale-dev/cluster-api-provider-outscale.git/cloud/scope" "github.com/outscale-dev/cluster-api-provider-outscale.git/cloud/services/security" tag "github.com/outscale-dev/cluster-api-provider-outscale.git/cloud/tag" + "github.com/outscale-dev/cluster-api-provider-outscale.git/util/tele" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" "sigs.k8s.io/controller-runtime/pkg/reconcile" ) @@ -164,14 +165,17 @@ func reconcileRoute(ctx context.Context, clusterScope *scope.ClusterScope, route } var resourceId string var err error + ctx, _, routeTableDone := tele.StartSpanWithLogger(ctx, "controllers.OscClusterControllers.routeTableReconcile") if resourceType == "gateway" { resourceId, err = getInternetServiceResourceId(resourceName, clusterScope) if err != nil { + routeTableDone() return reconcile.Result{}, err } } else { resourceId, err = getNatResourceId(resourceName, clusterScope) if err != nil { + routeTableDone() return reconcile.Result{}, err } } @@ -180,6 +184,7 @@ func reconcileRoute(ctx context.Context, clusterScope *scope.ClusterScope, route clusterScope.Info("check if the desired route exist", "routename", routeName) routeTableFromRoute, err := routeTableSvc.GetRouteTableFromRoute(associateRouteTableId, resourceId, resourceType) if err != nil { + routeTableDone() return reconcile.Result{}, err } if routeTableFromRoute == nil { @@ -187,11 +192,13 @@ func reconcileRoute(ctx context.Context, clusterScope *scope.ClusterScope, route clusterScope.Info("Create the desired route", "routeName", routeName) routeTableFromRoute, err = routeTableSvc.CreateRoute(destinationIpRange, routeTablesRef.ResourceMap[routeTableName], resourceId, resourceType) if err != nil { + routeTableDone() return reconcile.Result{}, fmt.Errorf("%w Can not create route for Osccluster %s/%s", err, clusterScope.GetNamespace(), clusterScope.GetName()) } } routeRef.ResourceMap[routeName] = routeTableFromRoute.GetRouteTableId() + routeTableDone() return reconcile.Result{}, nil } @@ -207,19 +214,23 @@ func reconcileDeleteRoute(ctx context.Context, clusterScope *scope.ClusterScope, routeName := routeSpec.Name + "-" + clusterScope.GetUID() var resourceId string var err error + ctx, _, routeTableDone := tele.StartSpanWithLogger(ctx, "controllers.OscClusterReconciler.reconcileRouteTableDelete") if resourceType == "gateway" { resourceId, err = getInternetServiceResourceId(resourceName, clusterScope) if err != nil { + routeTableDone() return reconcile.Result{}, err } } else { resourceId, err = getNatResourceId(resourceName, clusterScope) if err != nil { + routeTableDone() return reconcile.Result{}, err } } routeTableId, err := getRouteResourceId(routeName, clusterScope) if err != nil { + routeTableDone() return reconcile.Result{}, err } destinationIpRange := routeSpec.Destination @@ -228,11 +239,13 @@ func reconcileDeleteRoute(ctx context.Context, clusterScope *scope.ClusterScope, clusterScope.Info("Check if the desired route still exist", "routeName", routeName) routeTableFromRoute, err := routeTableSvc.GetRouteTableFromRoute(associateRouteTableId, resourceId, resourceType) if err != nil { + routeTableDone() return reconcile.Result{}, err } if routeTableFromRoute == nil { clusterScope.Info("the desired route does not exist anymore", "routeName", routeName) controllerutil.RemoveFinalizer(osccluster, "oscclusters.infrastructure.cluster.x-k8s.io") + routeTableDone() return reconcile.Result{}, nil } clusterScope.Info("Delete Route") @@ -241,8 +254,10 @@ func reconcileDeleteRoute(ctx context.Context, clusterScope *scope.ClusterScope, clusterScope.Info("Delete the desired route", "routeName", routeName) err = routeTableSvc.DeleteRoute(destinationIpRange, routeTableId) if err != nil { + routeTableDone() return reconcile.Result{}, fmt.Errorf("%w Can not delete route for Osccluster %s/%s", err, clusterScope.GetNamespace(), clusterScope.GetName()) } + routeTableDone() return reconcile.Result{}, nil } @@ -258,16 +273,18 @@ func reconcileRouteTable(ctx context.Context, clusterScope *scope.ClusterScope, netSpec := clusterScope.GetNet() netSpec.SetDefaultValue() netName := netSpec.Name + "-" + clusterScope.GetUID() + netId, err := getNetResourceId(netName, clusterScope) if err != nil { return reconcile.Result{}, err } networkSpec := clusterScope.GetNetwork() clusterName := networkSpec.ClusterName + "-" + clusterScope.GetUID() - + ctx, _, routeTableDone := tele.StartSpanWithLogger(ctx, "controllers.OscClusterControllers.reconcileRouteTable") clusterScope.Info("Get list of all desired routetable in net", "netId", netId) routeTableIds, err := routeTableSvc.GetRouteTableIdsFromNetIds(netId) if err != nil { + routeTableDone() return reconcile.Result{}, err } for _, routeTableSpec := range routeTablesSpec { @@ -277,6 +294,7 @@ func reconcileRouteTable(ctx context.Context, clusterScope *scope.ClusterScope, subnetName := routeTableSpec.SubnetName + "-" + clusterScope.GetUID() subnetId, err := getSubnetResourceId(subnetName, clusterScope) if err != nil { + routeTableDone() return reconcile.Result{}, err } @@ -317,6 +335,7 @@ func reconcileRouteTable(ctx context.Context, clusterScope *scope.ClusterScope, clusterScope.Info("Create the desired routetable", "routeTableName", routeTableName) routeTable, err := routeTableSvc.CreateRouteTable(netId, clusterName, routeTableName) if err != nil { + routeTableDone() return reconcile.Result{}, fmt.Errorf("%w Can not create routetable for Osccluster %s/%s", err, clusterScope.GetNamespace(), clusterScope.GetName()) } @@ -324,6 +343,7 @@ func reconcileRouteTable(ctx context.Context, clusterScope *scope.ClusterScope, clusterScope.Info("Link the desired routetable with subnet", "routeTableName", routeTableName) linkRouteTableId, err := routeTableSvc.LinkRouteTable(routeTableId, subnetId) if err != nil { + routeTableDone() return reconcile.Result{}, fmt.Errorf("%w Can not link routetable with net for Osccluster %s/%s", err, clusterScope.GetNamespace(), clusterScope.GetName()) } clusterScope.Info("### Get routeTable ###", "routeTable", routeTable) @@ -336,11 +356,13 @@ func reconcileRouteTable(ctx context.Context, clusterScope *scope.ClusterScope, clusterScope.Info("Create route for the desired routetable", "routeTableName", routeTableName) _, err = reconcileRoute(ctx, clusterScope, routeSpec, routeTableName, routeTableSvc) if err != nil { + routeTableDone() return reconcile.Result{}, err } } } } + routeTableDone() return reconcile.Result{}, nil } @@ -358,17 +380,20 @@ func reconcileDeleteRouteTable(ctx context.Context, clusterScope *scope.ClusterS } routeTablesRef := clusterScope.GetRouteTablesRef() linkRouteTablesRef := clusterScope.GetLinkRouteTablesRef() + ctx, _, routeTableDone := tele.StartSpanWithLogger(ctx, "controllers.OscClusterControllers.reconcileDeleteRouteTable") netSpec := clusterScope.GetNet() netSpec.SetDefaultValue() netName := netSpec.Name + "-" + clusterScope.GetUID() netId, err := getNetResourceId(netName, clusterScope) if err != nil { + routeTableDone() return reconcile.Result{}, err } routeTableIds, err := routeTableSvc.GetRouteTableIdsFromNetIds(netId) if err != nil { + routeTableDone() return reconcile.Result{}, err } @@ -381,6 +406,7 @@ func reconcileDeleteRouteTable(ctx context.Context, clusterScope *scope.ClusterS if !Contains(routeTableIds, routeTableId) { clusterScope.Info("the desired routeTable does no exist anymore", "routeTableName", routeTableName) controllerutil.RemoveFinalizer(osccluster, "oscclusters.infrastructure.cluster.x-k8s.io") + routeTableDone() return reconcile.Result{}, nil } clusterScope.Info("Remove Route") @@ -388,20 +414,24 @@ func reconcileDeleteRouteTable(ctx context.Context, clusterScope *scope.ClusterS for _, routeSpec := range *routesSpec { _, err = reconcileDeleteRoute(ctx, clusterScope, routeSpec, routeTableName, routeTableSvc) if err != nil { + routeTableDone() return reconcile.Result{}, err } } clusterScope.Info("Unlink the desired routeTable", "routeTableName", routeTableName) err = routeTableSvc.UnlinkRouteTable(linkRouteTablesRef.ResourceMap[routeTableName]) if err != nil { + routeTableDone() return reconcile.Result{}, fmt.Errorf("%w Can not unlink routeTable for Osccluster %s/%s", err, clusterScope.GetNamespace(), clusterScope.GetName()) } clusterScope.Info("delete the desired routeTable", "routeTableName", routeTableName) err = routeTableSvc.DeleteRouteTable(routeTablesRef.ResourceMap[routeTableName]) if err != nil { + routeTableDone() return reconcile.Result{}, fmt.Errorf("%w Can not delete routeTable for Osccluster %s/%s", err, clusterScope.GetNamespace(), clusterScope.GetName()) } } + routeTableDone() return reconcile.Result{}, nil } diff --git a/controllers/osccluster_securitygroup_controller.go b/controllers/osccluster_securitygroup_controller.go index 8cd3b1239..538ec0ab0 100644 --- a/controllers/osccluster_securitygroup_controller.go +++ b/controllers/osccluster_securitygroup_controller.go @@ -29,6 +29,7 @@ import ( "github.com/outscale-dev/cluster-api-provider-outscale.git/cloud/scope" "github.com/outscale-dev/cluster-api-provider-outscale.git/cloud/services/security" tag "github.com/outscale-dev/cluster-api-provider-outscale.git/cloud/tag" + "github.com/outscale-dev/cluster-api-provider-outscale.git/util/tele" osc "github.com/outscale/osc-sdk-go/v2" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" "sigs.k8s.io/controller-runtime/pkg/reconcile" @@ -186,7 +187,9 @@ func reconcileSecurityGroupRule(ctx context.Context, clusterScope *scope.Cluster clusterScope.Info("### Get associateSecurityGroupId###", "securityGroup", associateSecurityGroupId) clusterScope.Info("check if the desired securityGroupRule exist", "securityGroupRuleName", securityGroupRuleName) securityGroupFromSecurityGroupRule, err := securityGroupSvc.GetSecurityGroupFromSecurityGroupRule(associateSecurityGroupId, Flow, IpProtocol, IpRange, "", FromPortRange, ToPortRange) + ctx, _, securityGroupDone := tele.StartSpanWithLogger(ctx, "controllers.OscClusterControllers.reconcileSecurityGroup") if err != nil { + securityGroupDone() return reconcile.Result{}, err } if securityGroupFromSecurityGroupRule == nil { @@ -194,11 +197,13 @@ func reconcileSecurityGroupRule(ctx context.Context, clusterScope *scope.Cluster clusterScope.Info("Create the desired securityGroupRule", "securityGroupRuleName", securityGroupRuleName) securityGroupFromSecurityGroupRule, err = securityGroupSvc.CreateSecurityGroupRule(associateSecurityGroupId, Flow, IpProtocol, IpRange, "", FromPortRange, ToPortRange) if err != nil { + securityGroupDone() return reconcile.Result{}, fmt.Errorf("%w Can not create securityGroupRule for OscCluster %s/%s", err, clusterScope.GetNamespace(), clusterScope.GetName()) } } securityGroupRuleRef.ResourceMap[securityGroupRuleName] = securityGroupFromSecurityGroupRule.GetSecurityGroupId() + securityGroupDone() return reconcile.Result{}, nil } @@ -255,8 +260,11 @@ func reconcileSecurityGroup(ctx context.Context, clusterScope *scope.ClusterScop netSpec := clusterScope.GetNet() netSpec.SetDefaultValue() netName := netSpec.Name + "-" + clusterScope.GetUID() + ctx, _, securityGroupDone := tele.StartSpanWithLogger(ctx, "controllers.OscClusterControllers.reconcileSecurityGroup") + netId, err := getNetResourceId(netName, clusterScope) if err != nil { + securityGroupDone() return reconcile.Result{}, err } networkSpec := clusterScope.GetNetwork() @@ -265,6 +273,7 @@ func reconcileSecurityGroup(ctx context.Context, clusterScope *scope.ClusterScop clusterScope.Info("Get list of all desired securitygroup in net", "netId", netId) securityGroupIds, err := securityGroupSvc.GetSecurityGroupIdsFromNetIds(netId) if err != nil { + securityGroupDone() return reconcile.Result{}, err } securityGroupsRef := clusterScope.GetSecurityGroupsRef() @@ -308,11 +317,13 @@ func reconcileSecurityGroup(ctx context.Context, clusterScope *scope.ClusterScop clusterScope.Info("Create securityGroupRule for the desired securityGroup", "securityGroupName", securityGroupName) _, err = reconcileSecurityGroupRule(ctx, clusterScope, securityGroupRuleSpec, securityGroupName, securityGroupSvc) if err != nil { + securityGroupDone() return reconcile.Result{}, err } } } } + securityGroupDone() return reconcile.Result{}, nil } @@ -367,6 +378,7 @@ func reconcileDeleteSecurityGroup(ctx context.Context, clusterScope *scope.Clust netSpec := clusterScope.GetNet() netSpec.SetDefaultValue() netName := netSpec.Name + "-" + clusterScope.GetUID() + netId, err := getNetResourceId(netName, clusterScope) if err != nil { return reconcile.Result{}, err @@ -375,6 +387,7 @@ func reconcileDeleteSecurityGroup(ctx context.Context, clusterScope *scope.Clust if err != nil { return reconcile.Result{}, err } + ctx, _, securityGroupDone := tele.StartSpanWithLogger(ctx, "controller.OscClusterReconciler.reconcilerDeleteSecurityGroup") clusterScope.Info("Delete SecurityGroup Info") clock_time := clock.New() for _, securityGroupSpec := range securityGroupsSpec { @@ -383,6 +396,7 @@ func reconcileDeleteSecurityGroup(ctx context.Context, clusterScope *scope.Clust if !Contains(securityGroupIds, securityGroupId) { clusterScope.Info("the desired securityGroup does not exist anymore", "securityGroupName", securityGroupName) controllerutil.RemoveFinalizer(osccluster, "oscclusters.infrastructure.cluster.x-k8s.io") + securityGroupDone() return reconcile.Result{}, nil } clusterScope.Info("Remove securityGroupRule") @@ -390,6 +404,7 @@ func reconcileDeleteSecurityGroup(ctx context.Context, clusterScope *scope.Clust for _, securityGroupRuleSpec := range *securityGroupRulesSpec { _, err = reconcileDeleteSecurityGroupRule(ctx, clusterScope, securityGroupRuleSpec, securityGroupName, securityGroupSvc) if err != nil { + securityGroupDone() return reconcile.Result{}, err } } @@ -397,8 +412,10 @@ func reconcileDeleteSecurityGroup(ctx context.Context, clusterScope *scope.Clust clusterScope.Info("delete the desired securityGroup", "securityGroupName", securityGroupName) _, err := deleteSecurityGroup(ctx, clusterScope, securityGroupsRef.ResourceMap[securityGroupName], securityGroupSvc, clock_time) if err != nil { + securityGroupDone() return reconcile.Result{}, fmt.Errorf("%w Can not delete securityGroup for Osccluster %s/%s", err, clusterScope.GetNamespace(), clusterScope.GetName()) } } + securityGroupDone() return reconcile.Result{}, nil } diff --git a/controllers/osccluster_subnet_controller.go b/controllers/osccluster_subnet_controller.go index 5a6ce83ae..0e9905d20 100644 --- a/controllers/osccluster_subnet_controller.go +++ b/controllers/osccluster_subnet_controller.go @@ -24,6 +24,7 @@ import ( "github.com/outscale-dev/cluster-api-provider-outscale.git/cloud/scope" "github.com/outscale-dev/cluster-api-provider-outscale.git/cloud/services/net" tag "github.com/outscale-dev/cluster-api-provider-outscale.git/cloud/tag" + "github.com/outscale-dev/cluster-api-provider-outscale.git/util/tele" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" "sigs.k8s.io/controller-runtime/pkg/reconcile" ) @@ -89,8 +90,10 @@ func reconcileSubnet(ctx context.Context, clusterScope *scope.ClusterScope, subn netSpec := clusterScope.GetNet() netSpec.SetDefaultValue() netName := netSpec.Name + "-" + clusterScope.GetUID() + ctx, _, subnetDone := tele.StartSpanWithLogger(ctx, "controllers.OscClusterControllers.reconcileSubnet") netId, err := getNetResourceId(netName, clusterScope) if err != nil { + subnetDone() return reconcile.Result{}, err } var subnetsSpec []*infrastructurev1beta1.OscSubnet @@ -102,6 +105,7 @@ func reconcileSubnet(ctx context.Context, clusterScope *scope.ClusterScope, subn var subnetIds []string subnetIds, err = subnetSvc.GetSubnetIdsFromNetIds(netId) if err != nil { + subnetDone() return reconcile.Result{}, err } for _, subnetSpec := range subnetsSpec { @@ -123,6 +127,7 @@ func reconcileSubnet(ctx context.Context, clusterScope *scope.ClusterScope, subn clusterScope.Info("Create the desired subnet", "subnetName", subnetName) subnet, err := subnetSvc.CreateSubnet(subnetSpec, netId, subnetName) if err != nil { + subnetDone() return reconcile.Result{}, fmt.Errorf("%w Can not create subnet for Osccluster %s/%s", err, clusterScope.GetNamespace(), clusterScope.GetName()) } clusterScope.Info("### Get subnet ###", "subnet", subnet) @@ -130,6 +135,7 @@ func reconcileSubnet(ctx context.Context, clusterScope *scope.ClusterScope, subn subnetSpec.ResourceId = subnet.GetSubnetId() } } + subnetDone() return reconcile.Result{}, nil } @@ -151,12 +157,15 @@ func reconcileDeleteSubnet(ctx context.Context, clusterScope *scope.ClusterScope } else { subnetsSpec = clusterScope.GetSubnet() } + ctx, _, subnetDone := tele.StartSpanWithLogger(ctx, "controllers.OscClusterReconciler.reconcileDeleteSubnet") netId, err := getNetResourceId(netName, clusterScope) if err != nil { + subnetDone() return reconcile.Result{}, err } subnetIds, err := subnetSvc.GetSubnetIdsFromNetIds(netId) if err != nil { + subnetDone() return reconcile.Result{}, err } for _, subnetSpec := range subnetsSpec { @@ -165,13 +174,16 @@ func reconcileDeleteSubnet(ctx context.Context, clusterScope *scope.ClusterScope if !Contains(subnetIds, subnetId) { clusterScope.Info("the desired subnet does not exist anymore", "subnetName", subnetName) controllerutil.RemoveFinalizer(osccluster, "oscclusters.infrastructure.cluster.x-k8s.io") + subnetDone() return reconcile.Result{}, nil } err = subnetSvc.DeleteSubnet(subnetId) if err != nil { clusterScope.Info("Delete te desired subnet", "subnetName", subnetName) + subnetDone() return reconcile.Result{}, fmt.Errorf("%w Can not delete subnet for Osccluster %s/%s", err, clusterScope.GetNamespace(), clusterScope.GetName()) } } + subnetDone() return reconcile.Result{}, nil } diff --git a/controllers/oscmachine_controller.go b/controllers/oscmachine_controller.go index 6cd6281fa..d98e51f5a 100644 --- a/controllers/oscmachine_controller.go +++ b/controllers/oscmachine_controller.go @@ -289,18 +289,13 @@ func (r *OscMachineReconciler) reconcile(ctx context.Context, machineScope *scop return reconcile.Result{}, checkVmVolumeSubregionNameErr } } - ctx, _, imageDone := tele.StartSpanWithLogger(ctx, "controllers.OscMachineController.imageReconcile") imageSvc := r.getImageSvc(ctx, *clusterScope) reconcileImage, err := reconcileImage(ctx, machineScope, imageSvc) if err != nil { machineScope.Error(err, "failed to reconcile Image") - imageDone() return reconcileImage, err } - imageDone() - - ctx, _, volumeDone := tele.StartSpanWithLogger(ctx, "controllers.OscMachineControllers.VolumeReconcile") volumeSvc := r.getVolumeSvc(ctx, *clusterScope) if len(machineScope.OscMachine.Spec.Node.Volumes) > 0 { @@ -309,46 +304,30 @@ func (r *OscMachineReconciler) reconcile(ctx context.Context, machineScope *scop if err != nil { machineScope.Error(err, "failed to reconcile volume") conditions.MarkFalse(oscmachine, infrastructurev1beta1.VolumeReadyCondition, infrastructurev1beta1.VolumeReconciliationFailedReason, clusterv1.ConditionSeverityWarning, err.Error()) - volumeDone() return reconcileVolume, err } } - volumeDone() - - ctx, _, keypairDone := tele.StartSpanWithLogger(ctx, "controllers.OscMachineControllers.KeypairReconcile") keypairSvc := r.getKeyPairSvc(ctx, *clusterScope) reconcileKeypair, err := reconcileKeypair(ctx, machineScope, keypairSvc) if err != nil { machineScope.Error(err, "failed to reconcile keypair") - keypairDone() return reconcileKeypair, err } - keypairDone() - - ctx, _, publicIpDone := tele.StartSpanWithLogger(ctx, "controllers.OscMachineControllers.PublicIpReconcile") publicIpSvc := r.getPublicIpSvc(ctx, *clusterScope) - publicIpDone() - ctx, _, vmDone := tele.StartSpanWithLogger(ctx, "controllers.OscMachineControllers.VmReconcile") vmSvc := r.getVmSvc(ctx, *clusterScope) - ctx, _, loadBalancerDone := tele.StartSpanWithLogger(ctx, "controllers.OscMachineControllers.LoadBalancerReconcile") loadBalancerSvc := r.getLoadBalancerSvc(ctx, *clusterScope) - loadBalancerDone() - ctx, _, securityGroupDone := tele.StartSpanWithLogger(ctx, "controllers.OscMachineControllers.SecurityGroupReconcile") securityGroupSvc := r.getSecurityGroupSvc(ctx, *clusterScope) - securityGroupDone() reconcileVm, err := reconcileVm(ctx, clusterScope, machineScope, vmSvc, volumeSvc, publicIpSvc, loadBalancerSvc, securityGroupSvc) if err != nil { machineScope.Error(err, "failed to reconcile vm") conditions.MarkFalse(oscmachine, infrastructurev1beta1.VmReadyCondition, infrastructurev1beta1.VmNotReadyReason, clusterv1.ConditionSeverityWarning, err.Error()) - vmDone() return reconcileVm, err } - vmDone() conditions.MarkTrue(oscmachine, infrastructurev1beta1.VolumeReadyCondition) vmState := machineScope.GetVmState() @@ -396,37 +375,22 @@ func (r *OscMachineReconciler) reconcileDelete(ctx context.Context, machineScope } } - ctx, _, publicIpDone := tele.StartSpanWithLogger(ctx, "controllers.OscMachineReconciler.reconcilePublicIpDelete") - publicIpSvc := r.getPublicIpSvc(ctx, *clusterScope) - publicIpDone() - ctx, _, vmDone := tele.StartSpanWithLogger(ctx, "controllers.OscMachineReconciler.reconcileVmDelete") vmSvc := r.getVmSvc(ctx, *clusterScope) - ctx, _, loadBalancerDone := tele.StartSpanWithLogger(ctx, "controllers.OscMachineReconciler.reconcileLoadBalancerDelete") loadBalancerSvc := r.getLoadBalancerSvc(ctx, *clusterScope) - loadBalancerDone() - ctx, _, securityGroupDone := tele.StartSpanWithLogger(ctx, "controller.OscMachineReconciler.reconcileSecurityGroupDelete") - securityGroupSvc := r.getSecurityGroupSvc(ctx, *clusterScope) - securityGroupDone() reconcileDeleteVm, err := reconcileDeleteVm(ctx, clusterScope, machineScope, vmSvc, publicIpSvc, loadBalancerSvc, securityGroupSvc) if err != nil { - vmDone() return reconcileDeleteVm, err } - vmDone() - - ctx, _, keypairDone := tele.StartSpanWithLogger(ctx, "controller.OscMachineReconciler.reconcileKeyypairDelete") keypairSvc := r.getKeyPairSvc(ctx, *clusterScope) reconcileDeleteKeyPair, err := reconcileDeleteKeypair(ctx, machineScope, keypairSvc) if err != nil { - keypairDone() return reconcileDeleteKeyPair, err } - keypairDone() controllerutil.RemoveFinalizer(oscmachine, "oscmachine.infrastructure.cluster.x-k8s.io") return reconcile.Result{}, nil } diff --git a/controllers/oscmachine_image_controller.go b/controllers/oscmachine_image_controller.go index 9e437355c..a075cccb0 100644 --- a/controllers/oscmachine_image_controller.go +++ b/controllers/oscmachine_image_controller.go @@ -23,6 +23,7 @@ import ( infrastructurev1beta1 "github.com/outscale-dev/cluster-api-provider-outscale.git/api/v1beta1" "github.com/outscale-dev/cluster-api-provider-outscale.git/cloud/scope" "github.com/outscale-dev/cluster-api-provider-outscale.git/cloud/services/compute" + "github.com/outscale-dev/cluster-api-provider-outscale.git/util/tele" osc "github.com/outscale/osc-sdk-go/v2" "sigs.k8s.io/controller-runtime/pkg/reconcile" ) @@ -71,14 +72,17 @@ func reconcileImage(ctx context.Context, machineScope *scope.MachineScope, image imageRef.ResourceMap = make(map[string]string) } + ctx, _, imageDone := tele.StartSpanWithLogger(ctx, "controllers.OscMachineController.reconcileImage") if imageName != "" { machineScope.Info("########### Image Names exist", "imageName", imageName) if imageId, err = imageSvc.GetImageId(imageName); err != nil { + imageDone() return reconcile.Result{}, err } } else { machineScope.Info("########### Image Name is empty and we wiqqll try to get it from Id#####", "imageId", imageId) if imageName, err = imageSvc.GetImageName(imageId); err != nil { + imageDone() return reconcile.Result{}, err } } @@ -87,14 +91,16 @@ func reconcileImage(ctx context.Context, machineScope *scope.MachineScope, image } if image, err = imageSvc.GetImage(imageId); err != nil { + imageDone() return reconcile.Result{}, err } if image == nil || imageSpec.ResourceId == "" { machineScope.Info("########### Image is nil") - + imageDone() return reconcile.Result{}, err } else { imageRef.ResourceMap[imageName] = imageSpec.ResourceId } + imageDone() return reconcile.Result{}, nil } diff --git a/controllers/oscmachine_keypair_controller.go b/controllers/oscmachine_keypair_controller.go index 818c5368b..db2bf1158 100644 --- a/controllers/oscmachine_keypair_controller.go +++ b/controllers/oscmachine_keypair_controller.go @@ -26,6 +26,7 @@ import ( "github.com/outscale-dev/cluster-api-provider-outscale.git/cloud/scope" "github.com/outscale-dev/cluster-api-provider-outscale.git/cloud/services/security" "github.com/outscale-dev/cluster-api-provider-outscale.git/cloud/tag" + "github.com/outscale-dev/cluster-api-provider-outscale.git/util/tele" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" "sigs.k8s.io/controller-runtime/pkg/reconcile" ) @@ -78,6 +79,7 @@ func reconcileKeypair(ctx context.Context, machineScope *scope.MachineScope, key keypairRef.ResourceMap = make(map[string]string) } keypairRef.ResourceMap[keypairName] = keypairName + ctx, _, keypairDone := tele.StartSpanWithLogger(ctx, "controllers.OscMachineControllers.reconcileKeypair") if keypair, err = keypairSvc.GetKeyPair(keypairName); err != nil { machineScope.Info("######### fail to get keypair #####", "keypair", keypairSpec.Name) @@ -87,6 +89,7 @@ func reconcileKeypair(ctx context.Context, machineScope *scope.MachineScope, key machineScope.Info("######### key pair will be created #####", "keypair", keypairSpec.Name) _, err := keypairSvc.CreateKeyPair(keypairName) if err != nil { + keypairDone() return reconcile.Result{}, err } } else if keypairSpec.ResourceId == "" { @@ -94,6 +97,7 @@ func reconcileKeypair(ctx context.Context, machineScope *scope.MachineScope, key keypairRef.ResourceMap[keypairName] = keypairName } machineScope.Info("######## Get Keypair after reconcile keypair ######", "keypair", keypairSpec.Name) + keypairDone() return reconcile.Result{}, nil } @@ -104,12 +108,15 @@ func reconcileDeleteKeypair(ctx context.Context, machineScope *scope.MachineScop keypairSpec := machineScope.GetKeypair() keypairName := keypairSpec.Name + ctx, _, keypairDone := tele.StartSpanWithLogger(ctx, "controller.OscMachineReconciler.reconcileDeleteKeypair") keypair, err := keypairSvc.GetKeyPair(keypairName) if err != nil { + keypairDone() return reconcile.Result{}, err } if keypair == nil { controllerutil.RemoveFinalizer(oscmachine, "") + keypairDone() return reconcile.Result{}, err } deleteKeypair := machineScope.GetDeleteKeypair() @@ -117,11 +124,12 @@ func reconcileDeleteKeypair(ctx context.Context, machineScope *scope.MachineScop machineScope.Info("Remove keypair") err = keypairSvc.DeleteKeyPair(keypairName) if err != nil { + keypairDone() return reconcile.Result{}, fmt.Errorf("Can not delete keypair for OscCluster %s/%s", machineScope.GetNamespace(), machineScope.GetName()) } } else { machineScope.Info("Keep keypair") } - + keypairDone() return reconcile.Result{}, nil } diff --git a/controllers/oscmachine_vm_controller.go b/controllers/oscmachine_vm_controller.go index 84bd1c1e5..13243edf0 100644 --- a/controllers/oscmachine_vm_controller.go +++ b/controllers/oscmachine_vm_controller.go @@ -26,6 +26,7 @@ import ( "github.com/outscale-dev/cluster-api-provider-outscale.git/cloud/services/service" "github.com/outscale-dev/cluster-api-provider-outscale.git/cloud/services/storage" tag "github.com/outscale-dev/cluster-api-provider-outscale.git/cloud/tag" + "github.com/outscale-dev/cluster-api-provider-outscale.git/util/tele" osc "github.com/outscale/osc-sdk-go/v2" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" @@ -296,6 +297,7 @@ func reconcileVm(ctx context.Context, clusterScope *scope.ClusterScope, machineS vmSpec := machineScope.GetVm() vmRef := machineScope.GetVmRef() vmName := vmSpec.Name + "-" + machineScope.GetUID() + ctx, _, vmDone := tele.StartSpanWithLogger(ctx, "controllers.OscMachineControllers.reconcileVm") var volumeId string var err error @@ -303,6 +305,7 @@ func reconcileVm(ctx context.Context, clusterScope *scope.ClusterScope, machineS volumeName := vmSpec.VolumeName + "-" + machineScope.GetUID() volumeId, err = getVolumeResourceId(volumeName, machineScope) if err != nil { + vmDone() return reconcile.Result{}, err } } @@ -310,6 +313,7 @@ func reconcileVm(ctx context.Context, clusterScope *scope.ClusterScope, machineS subnetName := vmSpec.SubnetName + "-" + clusterScope.GetUID() subnetId, err := getSubnetResourceId(subnetName, clusterScope) if err != nil { + vmDone() return reconcile.Result{}, err } @@ -320,6 +324,7 @@ func reconcileVm(ctx context.Context, clusterScope *scope.ClusterScope, machineS vmPublicIpName = vmSpec.PublicIpName + "-" + clusterScope.GetUID() publicIpId, err = getPublicIpResourceId(vmPublicIpName, clusterScope) if err != nil { + vmDone() return reconcile.Result{}, err } linkPublicIpRef = machineScope.GetLinkPublicIpRef() @@ -343,6 +348,7 @@ func reconcileVm(ctx context.Context, clusterScope *scope.ClusterScope, machineS securityGroupName := vmSecurityGroup.Name + "-" + clusterScope.GetUID() securityGroupId, err := getSecurityGroupResourceId(securityGroupName, clusterScope) if err != nil { + vmDone() return reconcile.Result{}, err } machineScope.Info("get securityGroupId", "securityGroupId", securityGroupId) @@ -367,20 +373,24 @@ func reconcileVm(ctx context.Context, clusterScope *scope.ClusterScope, machineS machineScope.Info("### Get VmId ####", "vm", vmRef.ResourceMap) vm, err = vmSvc.GetVm(vmId) if err != nil { + vmDone() return reconcile.Result{}, err } clusterName := vmSpec.ClusterName + "-" + clusterScope.GetUID() privateDnsName, ok := vm.GetPrivateDnsNameOk() if !ok { + vmDone() return reconcile.Result{}, fmt.Errorf("Can not found privateDnsName %s/%s", machineScope.GetNamespace(), machineScope.GetName()) } err = vmSvc.AddCcmTag(clusterName, *privateDnsName, vmId) if err != nil { + vmDone() return reconcile.Result{}, fmt.Errorf("%w can not add ccm tag %s/%s", err, machineScope.GetNamespace(), machineScope.GetName()) } vmState, err := vmSvc.GetVmState(vmId) if err != nil { machineScope.SetVmState(infrastructurev1beta1.VmState("unknown")) + vmDone() return reconcile.Result{}, fmt.Errorf("%w Can not get vm %s state for OscMachine %s/%s", err, vmId, machineScope.GetNamespace(), machineScope.GetName()) } machineScope.SetVmState(infrastructurev1beta1.VmState(vmState)) @@ -397,12 +407,14 @@ func reconcileVm(ctx context.Context, clusterScope *scope.ClusterScope, machineS vm, err := vmSvc.CreateVm(machineScope, vmSpec, subnetId, securityGroupIds, privateIps, vmName) if err != nil { + vmDone() return reconcile.Result{}, fmt.Errorf("%w Can not create vm for OscMachine %s/%s", err, machineScope.GetNamespace(), machineScope.GetName()) } vmID = vm.GetVmId() err = vmSvc.CheckVmState(5, 120, "running", vmID) if err != nil { + vmDone() return reconcile.Result{}, fmt.Errorf("%w Can not get vm %s running for OscMachine %s/%s", err, vmID, machineScope.GetNamespace(), machineScope.GetName()) } machineScope.Info("Vm is running", "vmId", vmID) @@ -410,22 +422,26 @@ func reconcileVm(ctx context.Context, clusterScope *scope.ClusterScope, machineS if vmSpec.VolumeName != "" { err = volumeSvc.CheckVolumeState(5, 60, "available", volumeId) if err != nil { + vmDone() return reconcile.Result{}, fmt.Errorf("%w Can not get volume %s available for OscMachine %s/%s", err, volumeId, machineScope.GetNamespace(), machineScope.GetName()) } machineScope.Info("Volume is available", "volumeId", volumeId) err = volumeSvc.LinkVolume(volumeId, vmID, vmVolumeDeviceName) if err != nil { + vmDone() return reconcile.Result{}, fmt.Errorf("%w Can not link volume %s with vm %s for OscMachine %s/%s", err, volumeId, vmID, machineScope.GetNamespace(), machineScope.GetName()) } machineScope.Info("Volume is linked", "volumeId", volumeId) err = volumeSvc.CheckVolumeState(5, 60, "in-use", volumeId) machineScope.Info("Volume is in-use", "volumeId", volumeId) if err != nil { + vmDone() return reconcile.Result{}, fmt.Errorf("%w Can not get volume %s in use for OscMachine %s/%s", err, volumeId, machineScope.GetNamespace(), machineScope.GetName()) } } err = vmSvc.CheckVmState(5, 60, "running", vmID) if err != nil { + vmDone() return reconcile.Result{}, fmt.Errorf("%w Can not get vm %s running for OscMachine %s/%s", err, vmID, machineScope.GetNamespace(), machineScope.GetName()) } machineScope.Info("Vm is running again", "vmId", vmID) @@ -433,6 +449,7 @@ func reconcileVm(ctx context.Context, clusterScope *scope.ClusterScope, machineS if vmSpec.PublicIpName != "" { linkPublicIpId, err := publicIpSvc.LinkPublicIp(publicIpId, vmID) if err != nil { + vmDone() return reconcile.Result{}, fmt.Errorf("%w Can not link publicIp %s with %s for OscCluster %s/%s", err, publicIpId, vmID, machineScope.GetNamespace(), machineScope.GetName()) } machineScope.Info("Link public ip", "linkPublicIpId", linkPublicIpId) @@ -440,6 +457,7 @@ func reconcileVm(ctx context.Context, clusterScope *scope.ClusterScope, machineS err = vmSvc.CheckVmState(5, 60, "running", vmID) if err != nil { + vmDone() return reconcile.Result{}, fmt.Errorf("%w Can not get vm %s running for OscMachine %s/%s", err, vmID, machineScope.GetNamespace(), machineScope.GetName()) } } @@ -448,6 +466,7 @@ func reconcileVm(ctx context.Context, clusterScope *scope.ClusterScope, machineS vmIds := []string{vmID} err := loadBalancerSvc.LinkLoadBalancerBackendMachines(vmIds, loadBalancerName) if err != nil { + vmDone() return reconcile.Result{}, fmt.Errorf("%w Can not link vm %s with loadBalancerName %s for OscCluster %s/%s", err, loadBalancerName, vmID, machineScope.GetNamespace(), machineScope.GetName()) } machineScope.Info("Create LoadBalancer Sg") @@ -466,21 +485,25 @@ func reconcileVm(ctx context.Context, clusterScope *scope.ClusterScope, machineS machineScope.Info("Get sg", "associateSecurityGroupId", associateSecurityGroupId) securityGroupFromSecurityGroupOutboundRule, err := securityGroupSvc.GetSecurityGroupFromSecurityGroupRule(associateSecurityGroupId, "Outbound", ipProtocol, "", securityGroupIds[0], fromPortRange, toPortRange) if err != nil { + vmDone() return reconcile.Result{}, fmt.Errorf("%w Can not get outbound securityGroupRule for OscCluster %s/%s", err, clusterScope.GetNamespace(), clusterScope.GetName()) } if securityGroupFromSecurityGroupOutboundRule == nil { _, err = securityGroupSvc.CreateSecurityGroupRule(associateSecurityGroupId, "Outbound", ipProtocol, "", securityGroupIds[0], fromPortRange, toPortRange) if err != nil { + vmDone() return reconcile.Result{}, fmt.Errorf("%w Can not create outbound securityGroupRule for OscCluster %s/%s", err, clusterScope.GetNamespace(), clusterScope.GetName()) } } securityGroupFromSecurityGroupInboundRule, err := securityGroupSvc.GetSecurityGroupFromSecurityGroupRule(securityGroupIds[0], "Inbound", ipProtocol, "", associateSecurityGroupId, fromPortRange, toPortRange) if err != nil { + vmDone() return reconcile.Result{}, fmt.Errorf("%w Can not get inbound securityGroupRule for OscCluster %s/%s", err, clusterScope.GetNamespace(), clusterScope.GetName()) } if securityGroupFromSecurityGroupInboundRule == nil { _, err = securityGroupSvc.CreateSecurityGroupRule(securityGroupIds[0], "Inbound", ipProtocol, "", associateSecurityGroupId, fromPortRange, toPortRange) if err != nil { + vmDone() return reconcile.Result{}, fmt.Errorf("%w Can not create inbound securityGroupRule for OscCluster %s/%s", err, clusterScope.GetNamespace(), clusterScope.GetName()) } } @@ -491,6 +514,7 @@ func reconcileVm(ctx context.Context, clusterScope *scope.ClusterScope, machineS vmSpec.ResourceId = vmID machineScope.SetProviderID(vmID) } + vmDone() return reconcile.Result{}, nil } @@ -503,10 +527,13 @@ func reconcileDeleteVm(ctx context.Context, clusterScope *scope.ClusterScope, ma vmSpec.SetDefaultValue() vmId := vmSpec.ResourceId machineScope.Info("### VmiD ###", "vmId", vmId) + ctx, _, vmDone := tele.StartSpanWithLogger(ctx, "controllers.OscMachineReconciler.reconcileDeleteVm") + vmName := vmSpec.Name if vmSpec.ResourceId == "" { machineScope.Info("The desired vm is currently destroyed", "vmName", vmName) controllerutil.RemoveFinalizer(oscmachine, "") + vmDone() return reconcile.Result{}, nil } keypairSpec := machineScope.GetKeypair() @@ -515,6 +542,7 @@ func reconcileDeleteVm(ctx context.Context, clusterScope *scope.ClusterScope, ma vm, err := vmSvc.GetVm(vmId) if err != nil { + vmDone() return reconcile.Result{}, err } @@ -524,6 +552,7 @@ func reconcileDeleteVm(ctx context.Context, clusterScope *scope.ClusterScope, ma securityGroupName := vmSecurityGroup.Name + "-" + clusterScope.GetUID() securityGroupId, err := getSecurityGroupResourceId(securityGroupName, clusterScope) if err != nil { + vmDone() return reconcile.Result{}, err } securityGroupIds = append(securityGroupIds, securityGroupId) @@ -531,6 +560,7 @@ func reconcileDeleteVm(ctx context.Context, clusterScope *scope.ClusterScope, ma if vm == nil { machineScope.Info("The desired vm does not exist anymore", "vmName", vmName) controllerutil.RemoveFinalizer(oscmachine, "") + vmDone() return reconcile.Result{}, nil } if vmSpec.PublicIpName != "" { @@ -538,10 +568,12 @@ func reconcileDeleteVm(ctx context.Context, clusterScope *scope.ClusterScope, ma publicIpName := vmSpec.PublicIpName + "-" + clusterScope.GetUID() err = vmSvc.CheckVmState(5, 120, "running", vmId) if err != nil { + vmDone() return reconcile.Result{}, fmt.Errorf("%w Can not get vm %s running for OscMachine %s/%s", err, vmId, machineScope.GetNamespace(), machineScope.GetName()) } err = publicIpSvc.UnlinkPublicIp(linkPublicIpRef.ResourceMap[publicIpName]) if err != nil { + vmDone() return reconcile.Result{}, fmt.Errorf("%w Can not unlink publicIp for OscCluster %s/%s", err, machineScope.GetNamespace(), machineScope.GetName()) } @@ -549,12 +581,14 @@ func reconcileDeleteVm(ctx context.Context, clusterScope *scope.ClusterScope, ma if vmSpec.LoadBalancerName != "" { err = vmSvc.CheckVmState(5, 60, "running", vmId) if err != nil { + vmDone() return reconcile.Result{}, fmt.Errorf("%w Can not get vm %s running for OscMachine %s/%s", err, vmId, machineScope.GetNamespace(), machineScope.GetName()) } vmIds := []string{vmId} loadBalancerName := vmSpec.LoadBalancerName err := loadBalancerSvc.UnlinkLoadBalancerBackendMachines(vmIds, loadBalancerName) if err != nil { + vmDone() return reconcile.Result{}, fmt.Errorf("%w Can not unlink vm %s with loadBalancerName %s for OscCluster %s/%s", err, loadBalancerName, vmId, machineScope.GetNamespace(), machineScope.GetName()) } clusterScope.Info("Get list OscMachine") @@ -567,6 +601,7 @@ func reconcileDeleteVm(ctx context.Context, clusterScope *scope.ClusterScope, ma if vmSpec.Replica != 1 { machines, _, err = clusterScope.ListMachines(ctx) if err != nil { + vmDone() return reconcile.Result{}, fmt.Errorf("%w Can not get ListMachine", err) } machineSize = len(machines) @@ -603,6 +638,7 @@ func reconcileDeleteVm(ctx context.Context, clusterScope *scope.ClusterScope, ma if machineCount != 1 { machineScope.SetDeleteKeypair(false) machineScope.Info("Keep Keypair from vm") + vmDone() return reconcile.Result{RequeueAfter: 30 * time.Second}, nil } if machineKcpCount == 1 { @@ -623,10 +659,12 @@ func reconcileDeleteVm(ctx context.Context, clusterScope *scope.ClusterScope, ma machineScope.Info("Get sg id", "securityGroupIds", securityGroupIds[0]) err = securityGroupSvc.DeleteSecurityGroupRule(associateSecurityGroupId, "Outbound", ipProtocol, "", securityGroupIds[0], fromPortRange, toPortRange) if err != nil { + vmDone() return reconcile.Result{}, fmt.Errorf("%w Can not delete outbound securityGroupRule for OscCluster %s/%s", err, clusterScope.GetNamespace(), clusterScope.GetName()) } err = securityGroupSvc.DeleteSecurityGroupRule(securityGroupIds[0], "Inbound", ipProtocol, "", securityGroupIds[0], fromPortRange, toPortRange) if err != nil { + vmDone() return reconcile.Result{}, fmt.Errorf("%w Can not delete inbound securityGroupRule for OscCluster %s/%s", err, clusterScope.GetNamespace(), clusterScope.GetName()) } @@ -640,7 +678,9 @@ func reconcileDeleteVm(ctx context.Context, clusterScope *scope.ClusterScope, ma vmSpec.ResourceId = "" machineScope.Info("Delete the desired vm", "vmName", vmName) if err != nil { + vmDone() return reconcile.Result{}, fmt.Errorf("%w Can not delete vm for OscMachine %s/%s", err, machineScope.GetNamespace(), machineScope.GetName()) } + vmDone() return reconcile.Result{}, nil } diff --git a/controllers/oscmachine_volume_controller.go b/controllers/oscmachine_volume_controller.go index d3d877979..23f97b53d 100644 --- a/controllers/oscmachine_volume_controller.go +++ b/controllers/oscmachine_volume_controller.go @@ -21,11 +21,11 @@ import ( "fmt" infrastructurev1beta1 "github.com/outscale-dev/cluster-api-provider-outscale.git/api/v1beta1" + "github.com/outscale-dev/cluster-api-provider-outscale.git/cloud/scope" "github.com/outscale-dev/cluster-api-provider-outscale.git/cloud/services/storage" tag "github.com/outscale-dev/cluster-api-provider-outscale.git/cloud/tag" + "github.com/outscale-dev/cluster-api-provider-outscale.git/util/tele" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" - - "github.com/outscale-dev/cluster-api-provider-outscale.git/cloud/scope" "sigs.k8s.io/controller-runtime/pkg/reconcile" ) @@ -117,6 +117,7 @@ func reconcileVolume(ctx context.Context, machineScope *scope.MachineScope, volu volumeIds = append(volumeIds, volumeId) } + ctx, _, volumeDone := tele.StartSpanWithLogger(ctx, "controllers.OscMachineControllers.reconcileVolume") machineScope.Info("Check if the desired volumes exist") validVolumeIds, err := volumeSvc.ValidateVolumeIds(volumeIds) if err != nil { @@ -135,6 +136,7 @@ func reconcileVolume(ctx context.Context, machineScope *scope.MachineScope, volu if !Contains(validVolumeIds, volumeId) { volume, err := volumeSvc.CreateVolume(volumeSpec, volumeName) if err != nil { + volumeDone() return reconcile.Result{}, fmt.Errorf("%w Can not create volume for OscMachine %s/%s", err, machineScope.GetNamespace(), machineScope.GetName()) } volumeId := volume.GetVolumeId() @@ -142,6 +144,7 @@ func reconcileVolume(ctx context.Context, machineScope *scope.MachineScope, volu if volumeId != "" { err = volumeSvc.CheckVolumeState(5, 60, "available", volumeId) if err != nil { + volumeDone() return reconcile.Result{}, fmt.Errorf("%w Can not get volume available for OscMachine %s/%s", err, machineScope.GetNamespace(), machineScope.GetName()) } machineScope.Info("Volume is available", "volumeId", volumeId) @@ -151,6 +154,7 @@ func reconcileVolume(ctx context.Context, machineScope *scope.MachineScope, volu volumeSpec.ResourceId = volume.GetVolumeId() } } + volumeDone() return reconcile.Result{}, nil } @@ -167,6 +171,7 @@ func reconcileDeleteVolume(ctx context.Context, machineScope *scope.MachineScope } else { volumesSpec = machineScope.GetVolume() } + ctx, _, volumeDone := tele.StartSpanWithLogger(ctx, "controllers.OscMachineReconciler.reconcileDeleteVolume") var volumeIds []string var volumeId string @@ -176,6 +181,7 @@ func reconcileDeleteVolume(ctx context.Context, machineScope *scope.MachineScope } validVolumeIds, err := volumeSvc.ValidateVolumeIds(volumeIds) if err != nil { + volumeDone() return reconcile.Result{}, err } machineScope.Info("### Check Id ###", "volume", volumeIds) @@ -184,22 +190,26 @@ func reconcileDeleteVolume(ctx context.Context, machineScope *scope.MachineScope volumeName := volumeSpec.Name + "-" + machineScope.GetUID() if !Contains(validVolumeIds, volumeId) { controllerutil.RemoveFinalizer(oscmachine, "") + volumeDone() return reconcile.Result{}, nil } err = volumeSvc.CheckVolumeState(5, 60, "in-use", volumeId) if err != nil { + volumeDone() return reconcile.Result{}, fmt.Errorf("%w Can not get volume %s in use for OscMachine %s/%s", err, volumeId, machineScope.GetNamespace(), machineScope.GetName()) } machineScope.Info("Volume is in use", "volumeId", volumeId) err = volumeSvc.UnlinkVolume(volumeId) if err != nil { + volumeDone() return reconcile.Result{}, fmt.Errorf("%w Can not unlink volume %s in use for OscMachine %s/%s", err, volumeId, machineScope.GetNamespace(), machineScope.GetName()) } machineScope.Info("Volume is unlinked", "volumeId", volumeId) err = volumeSvc.CheckVolumeState(5, 60, "available", volumeId) if err != nil { + volumeDone() return reconcile.Result{}, fmt.Errorf("%w Can not get volume %s available for OscMachine %s/%s", err, volumeId, machineScope.GetNamespace(), machineScope.GetName()) } machineScope.Info("Volume is available", "volumeId", volumeId) @@ -207,8 +217,10 @@ func reconcileDeleteVolume(ctx context.Context, machineScope *scope.MachineScope machineScope.Info("Delete the desired volume", "volumeName", volumeName) err = volumeSvc.DeleteVolume(volumeId) if err != nil { + volumeDone() return reconcile.Result{}, fmt.Errorf("%w Can not delete volume for OscMachine %s/%s", err, machineScope.GetNamespace(), machineScope.GetName()) } } + volumeDone() return reconcile.Result{}, nil } diff --git a/docs/src/SUMMARY.md b/docs/src/SUMMARY.md index 6f87b4ca0..d8a4e22c4 100644 --- a/docs/src/SUMMARY.md +++ b/docs/src/SUMMARY.md @@ -7,6 +7,7 @@ - [Troubleshooting](./topics/troubleshooting.md) - [Cluster-Autoscaler](./topics/cluster-autoscaler.md) - [How to config](./topics/config.md) + - [How to enable tracing](./topics/tracing.md) - [Development](./developers/develop.md) - [How to develop](./developers/developement.md) - [How to test](./developers/e2e.md) diff --git a/docs/src/topics/tracing.md b/docs/src/topics/tracing.md new file mode 100644 index 000000000..bb6a6d64e --- /dev/null +++ b/docs/src/topics/tracing.md @@ -0,0 +1,10 @@ +# Add tracing + +You can use Jaeger or Zipkin as backend for Opentelemetry. + +### activate opentracing + +Add in opentracing deployment: +``` +--enable-tracing +`` diff --git a/docs/src/topics/troubleshooting.md b/docs/src/topics/troubleshooting.md index 8cf3edd86..d9fea7b7a 100644 --- a/docs/src/topics/troubleshooting.md +++ b/docs/src/topics/troubleshooting.md @@ -38,7 +38,54 @@ Node are not ready because they need cni to be ready. If your vm is never in running phase and but still in provisonned phase, please look at the cloud init log of your vm. +### E2e test failed to launch +If e2e test doesn't launch when you run it: +``` +clusterctl init --core cluster-api --bootstrap kubeadm --control-plane kubeadm --infrastructure outscale +``` +and launched after and failed because it can not communicate with your cluster: +``` +clusterctl config cluster capo-yayi5z --infrastructure (default) --kubernetes-version v1.22.11 --control-plane-machine-count 1 --worker-machine-count 1 --flavor with-clusterclass +``` + +You can launch yourself. +Please use this config (~/.cluster-api/clusterctl.yaml): +```yaml + +CLUSTER_NAME: clusterctl +CLUSTER_NAMESPACE: default +CONTROL_PLANE_MACHINE_TEMPLATE_UPGRADE_TO: cp-k8s-upgrade-and-conformance +KUBERNETES_VERSION: v1.24.1 +KUBERNETES_VERSION_UPGRADE_FROM: v1.23.6 +KUBERNETES_VERSION_UPGRADE_TO: v1.24.1 +OSC_NET_NAME: clusterctl-net +WORKERS_MACHINE_TEMPLATE_UPGRADE_TO: worker-k8s-upgrade-and-conformance +overridesFolder: /root/cluster-api-provider-outscale/artifact/repository/overrides +providers: +- name: cluster-api + type: CoreProvider + url: /root/cluster-api-provider-outscale/artifact/repository/cluster-api/v1.1.4/components.yaml +- name: kubeadm + type: BootstrapProvider + url: /root/cluster-api-provider-outscale/artifact/repository/bootstrap-kubeadm/v1.1.4/components.yaml +- name: kubeadm + type: ControlPlaneProvider + url: /root/cluster-api-provider-outscale/artifact/repository/control-plane-kubeadm/v1.1.4/components.yaml +- name: outscale + type: InfrastructureProvider + url: /root/cluster-api-provider-outscale/artifact/repository/infrastructure-outscale/v0.1.99/components.yaml +``` +and launch this command before relaunch e2etest: +``` +clusterctl init --core cluster-api --bootstrap kubeadm --control-plane kubeadm --infrastructure outscale +``` + ### Clean Stack + +Please set the cluster name that you use: +``` +export ClusterToClean=hello-osc +``` If your vm never reach running, you can use ```bash ClusterToClean=my-cluster-name make testclean diff --git a/main.go b/main.go index de1f4df55..36ccf889e 100644 --- a/main.go +++ b/main.go @@ -102,17 +102,18 @@ func main() { os.Exit(1) } - ctx := ctrl.SetupSignalHandler() - if err := opentracing.RegisterTracing(ctx, setupLog); err != nil { - setupLog.Error(err, "unable to initialize tracing") - os.Exit(1) + ctx := ctrl.SetupSignalHandler() + if enableTracing { + if err := opentracing.RegisterTracing(ctx, setupLog); err != nil { + setupLog.Error(err, "unable to initialize tracing") + os.Exit(1) + } + + if err := opentracing.RegisterMetrics(); err != nil { + setupLog.Error(err, "unable to initiliaze metrics") + os.Exit(1) + } } - - if err := opentracing.RegisterMetrics(); err != nil { - setupLog.Error(err, "unable to initiliaze metrics") - os.Exit(1) - } - if err = (&controllers.OscMachineReconciler{ Client: mgr.GetClient(), Recorder: mgr.GetEventRecorderFor("oscmachine-controller"), diff --git a/util/tele/composite_logger.go b/util/tele/composite_logger.go index a9677e4b5..e9aeeee0e 100644 --- a/util/tele/composite_logger.go +++ b/util/tele/composite_logger.go @@ -1,3 +1,19 @@ +/* +Copyright 2022 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + package tele import ( diff --git a/util/tele/corr_id.go b/util/tele/corr_id.go index 8720d9edb..9b2c98b37 100644 --- a/util/tele/corr_id.go +++ b/util/tele/corr_id.go @@ -1,3 +1,19 @@ +/* +Copyright 2022 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + package tele import ( diff --git a/util/tele/span_logger.go b/util/tele/span_logger.go index 908d5283c..1aefdcab2 100644 --- a/util/tele/span_logger.go +++ b/util/tele/span_logger.go @@ -1,3 +1,19 @@ +/* +Copyright 2022 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + package tele import ( diff --git a/util/tele/tele.go b/util/tele/tele.go index f1422df78..059604318 100644 --- a/util/tele/tele.go +++ b/util/tele/tele.go @@ -1,3 +1,19 @@ +/* +Copyright 2022 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + package tele import ( diff --git a/util/tracing/tracing.go b/util/tracing/tracing.go index bec2b8f67..88c1d5fa6 100644 --- a/util/tracing/tracing.go +++ b/util/tracing/tracing.go @@ -1,3 +1,19 @@ +/* +Copyright 2022 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + package tracing import (