Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion cmd/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,21 @@ import (
"encoding/pem"
"fmt"
"net/http"
"time"

"github.com/cert-manager/cert-manager/pkg/client/informers/externalversions"
"github.com/cert-manager/csi-lib/driver"
"github.com/cert-manager/csi-lib/manager"
"github.com/cert-manager/csi-lib/manager/util"
"github.com/cert-manager/csi-lib/metadata"
csimetrics "github.com/cert-manager/csi-lib/metrics"
"github.com/cert-manager/csi-lib/storage"
"github.com/prometheus/client_golang/prometheus"
"github.com/spf13/cobra"
"golang.org/x/sync/errgroup"
"k8s.io/utils/clock"
ctrl "sigs.k8s.io/controller-runtime"
ctrlmetrics "sigs.k8s.io/controller-runtime/pkg/metrics"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"

"github.com/cert-manager/csi-driver/cmd/app/options"
Expand All @@ -45,7 +50,8 @@ import (
)

const (
helpOutput = "Container Storage Interface driver to issue certificates from cert-manager"
helpOutput = "Container Storage Interface driver to issue certificates from cert-manager"
certRequestSharedInformerResyncPeriod = 5 * time.Second // TODO add to config if needed
)

// NewCommand will return a new command instance for the cert-manager CSI driver.
Expand Down Expand Up @@ -80,6 +86,18 @@ func NewCommand(ctx context.Context) *cobra.Command {
clientForMeta = util.ClientForMetadataTokenRequestEmptyAud(opts.RestConfig)
}

// Setup metrics handler to track metrics for cert-manager CertificateRequests
// Note, it won't be started if the --metrics-bind-address is "0".
certRequestInformerFactory := externalversions.NewSharedInformerFactory(opts.CMClient, certRequestSharedInformerResyncPeriod)
certRequestInformer := certRequestInformerFactory.Certmanager().V1().CertificateRequests()
metricsHandler := csimetrics.New(
opts.NodeID,
&opts.Logr,
ctrlmetrics.Registry.(*prometheus.Registry),
store,
certRequestInformer.Lister(),
)

mngrlog := opts.Logr.WithName("manager")
d, err := driver.New(ctx, opts.Endpoint, opts.Logr.WithName("driver"), driver.Options{
DriverName: opts.DriverName,
Expand All @@ -97,6 +115,7 @@ func NewCommand(ctx context.Context) *cobra.Command {
GenerateRequest: requestgen.RequestForMetadata,
SignRequest: signRequest,
WriteKeypair: writer.WriteKeypair,
Metrics: metricsHandler,
}),
})
if err != nil {
Expand Down Expand Up @@ -163,6 +182,12 @@ func NewCommand(ctx context.Context) *cobra.Command {
g.Go(func() error {
return metricsServer.Start(gCTX)
})

g.Go(func() error {
certRequestInformerFactory.Start(gCTX.Done())
certRequestInformerFactory.WaitForCacheSync(gCTX.Done())
return nil
})
}
return g.Wait()
},
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/go-logr/logr v1.4.3
github.com/onsi/ginkgo/v2 v2.27.5
github.com/onsi/gomega v1.39.0
github.com/prometheus/client_golang v1.23.2
github.com/spf13/cobra v1.10.2
github.com/spf13/pflag v1.0.10
github.com/stretchr/testify v1.11.1
Expand Down Expand Up @@ -70,7 +71,6 @@ require (
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.23.2 // indirect
github.com/prometheus/client_model v0.6.2 // indirect
github.com/prometheus/common v0.66.1 // indirect
github.com/prometheus/procfs v0.17.0 // indirect
Expand Down