diff --git a/internal/telemetry/telemetry.go b/internal/telemetry/telemetry.go index 7fa9510a8..7b1e057b3 100644 --- a/internal/telemetry/telemetry.go +++ b/internal/telemetry/telemetry.go @@ -16,6 +16,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" operatorv1alpha1 "github.com/kong/gateway-operator/api/v1alpha1" + operatorv1beta1 "github.com/kong/gateway-operator/api/v1beta1" "github.com/kong/gateway-operator/modules/manager/scheme" k8sutils "github.com/kong/gateway-operator/pkg/utils/kubernetes" ) @@ -105,34 +106,50 @@ func createManager( } // Add cluster state workflow { + checker := k8sutils.CRDChecker{Client: cl} + + cpExists, err := checker.CRDExists(operatorv1beta1.ControlPlaneGVR()) + if err != nil { + log.Info("failed to check if controlplane CRD exists", "error", err) + } + aiGatewayExists, err := checker.CRDExists(operatorv1alpha1.AIGatewayGVR()) + if err != nil { + log.Info("failed to check if aigateway CRD exists", "error", err) + } + dpExists, err := checker.CRDExists(operatorv1beta1.DataPlaneGVR()) + if err != nil { + log.Info("failed to check if dataplane CRD exists", "error", err) + } + w, err := telemetry.NewClusterStateWorkflow(dyn, cl.RESTMapper()) if err != nil { return nil, fmt.Errorf("failed to create cluster state workflow: %w", err) } - // Add dataplane count provider to monitor number of dataplanes in the cluster. - p, err := NewDataPlaneCountProvider(dyn, cl.RESTMapper()) - if err != nil { - log.Info("failed to create dataplane count provider", "error", err) - } else { - w.AddProvider(p) + if dpExists { + // Add dataplane count provider to monitor number of dataplanes in the cluster. + p, err := NewDataPlaneCountProvider(dyn, cl.RESTMapper()) + if err != nil { + log.Info("failed to create dataplane count provider", "error", err) + } else { + w.AddProvider(p) + } } - // Add controlplane count provider to monitor number of controlplanes in the cluster. - p, err = NewControlPlaneCountProvider(dyn, cl.RESTMapper()) - if err != nil { - log.Info("failed to create controlplane count provider", "error", err) - } else { - w.AddProvider(p) + if cpExists { + // Add controlplane count provider to monitor number of controlplanes in the cluster. + p, err := NewControlPlaneCountProvider(dyn, cl.RESTMapper()) + if err != nil { + log.Info("failed to create controlplane count provider", "error", err) + } else { + w.AddProvider(p) + } } - checker := k8sutils.CRDChecker{Client: cl} // AIGateway is optional so check if it exists before enabling the count provider. - if exists, err := checker.CRDExists(operatorv1alpha1.AIGatewayGVR()); err != nil { - log.Info("failed to check if aigateway CRD exists ", "error", err) - } else if exists { + if aiGatewayExists { // Add aigateway count provider to monitor number of aigateways in the cluster. - p, err = NewAIgatewayCountProvider(dyn, cl.RESTMapper()) + p, err := NewAIgatewayCountProvider(dyn, cl.RESTMapper()) if err != nil { log.Info("failed to create aigateway count provider", "error", err) } else { @@ -140,36 +157,44 @@ func createManager( } } - // Add dataplane count not from gateway. - p, err = NewStandaloneDataPlaneCountProvider(cl) - if err != nil { - log.Info("failed to create standalone dataplane count provider", "error", err) - } else { - w.AddProvider(p) + if dpExists { + // Add dataplane count not from gateway. + p, err := NewStandaloneDataPlaneCountProvider(cl) + if err != nil { + log.Info("failed to create standalone dataplane count provider", "error", err) + } else { + w.AddProvider(p) + } } - // Add controlplane count not from gateway. - p, err = NewStandaloneControlPlaneCountProvider(cl) - if err != nil { - log.Info("failed to create standalone controlplane count provider", "error", err) - } else { - w.AddProvider(p) + if cpExists { + // Add controlplane count not from gateway. + p, err := NewStandaloneControlPlaneCountProvider(cl) + if err != nil { + log.Info("failed to create standalone controlplane count provider", "error", err) + } else { + w.AddProvider(p) + } } - // Add dataplane requested replicas count provider to monitor number of requested replicas for dataplanes. - p, err = NewDataPlaneRequestedReplicasCountProvider(cl) - if err != nil { - log.Info("failed to create dataplane requested replicas count provider", "error", err) - } else { - w.AddProvider(p) + if dpExists { + // Add dataplane requested replicas count provider to monitor number of requested replicas for dataplanes. + p, err := NewDataPlaneRequestedReplicasCountProvider(cl) + if err != nil { + log.Info("failed to create dataplane requested replicas count provider", "error", err) + } else { + w.AddProvider(p) + } } - // Add controlplane requested replicas count provider to monitor number of requested replicas for controlplanes. - p, err = NewControlPlaneRequestedReplicasCountProvider(cl) - if err != nil { - log.Info("failed to create controlplane requested replicas count provider", "error", err) - } else { - w.AddProvider(p) + if cpExists { + // Add controlplane requested replicas count provider to monitor number of requested replicas for controlplanes. + p, err := NewControlPlaneRequestedReplicasCountProvider(cl) + if err != nil { + log.Info("failed to create controlplane requested replicas count provider", "error", err) + } else { + w.AddProvider(p) + } } m.AddWorkflow(w)