diff --git a/internal/controller/admission/image_push.go b/internal/controller/admission/image_push.go index 17d926f3..0d696743 100644 --- a/internal/controller/admission/image_push.go +++ b/internal/controller/admission/image_push.go @@ -44,7 +44,7 @@ func (r *FalconAdmissionReconciler) PushImage(ctx context.Context, log logr.Logg image := image.NewImageRefresher(ctx, log, r.falconApiConfig(ctx, falconAdmission), pushAuth, falconAdmission.Spec.Registry.TLS.InsecureSkipVerify) version := falconAdmission.Spec.Version - tag, err := image.Refresh(registryUri, common.SensorTypeKac, version) + tag, err := image.Refresh(registryUri, falcon.KacSensor, version) if err != nil { return fmt.Errorf("Cannot push Falcon Admission Image: %v", err) } @@ -134,7 +134,7 @@ func (r *FalconAdmissionReconciler) registryUri(ctx context.Context, falconAdmis return "", err } - return falcon_registry.SensorImageURI(cloud, common.SensorTypeKac), nil + return falcon.FalconContainerSensorImageURI(cloud, falcon.KacSensor), nil default: return "", fmt.Errorf("Unrecognized registry type: %s", falconAdmission.Spec.Registry.Type) } @@ -199,7 +199,7 @@ func (r *FalconAdmissionReconciler) setImageTag(ctx context.Context, falconAdmis return "", err } - tag, err := registry.LastContainerTag(ctx, common.SensorTypeKac, falconAdmission.Spec.Version) + tag, err := registry.LastContainerTag(ctx, falcon.KacSensor, falconAdmission.Spec.Version) if err == nil { falconAdmission.Status.Sensor = common.ImageVersion(tag) } diff --git a/internal/controller/falcon_container/image_push.go b/internal/controller/falcon_container/image_push.go index e4eaa7a7..51618101 100644 --- a/internal/controller/falcon_container/image_push.go +++ b/internal/controller/falcon_container/image_push.go @@ -44,7 +44,7 @@ func (r *FalconContainerReconciler) PushImage(ctx context.Context, log logr.Logg image := image.NewImageRefresher(ctx, log, r.falconApiConfig(ctx, falconContainer), pushAuth, falconContainer.Spec.Registry.TLS.InsecureSkipVerify) version := falconContainer.Spec.Version - tag, err := image.Refresh(registryUri, common.SensorTypeSidecar, version) + tag, err := image.Refresh(registryUri, falcon.SidecarSensor, version) if err != nil { return fmt.Errorf("Cannot push Falcon Container Image: %v", err) } @@ -134,7 +134,7 @@ func (r *FalconContainerReconciler) registryUri(ctx context.Context, falconConta return "", err } - return falcon_registry.SensorImageURI(cloud, common.SensorTypeSidecar), nil + return falcon.FalconContainerSensorImageURI(cloud, falcon.SidecarSensor), nil default: return "", fmt.Errorf("Unrecognized registry type: %s", falconContainer.Spec.Registry.Type) } @@ -199,7 +199,7 @@ func (r *FalconContainerReconciler) setImageTag(ctx context.Context, falconConta return "", err } - tag, err := registry.LastContainerTag(ctx, common.SensorTypeSidecar, falconContainer.Spec.Version) + tag, err := registry.LastContainerTag(ctx, falcon.SidecarSensor, falconContainer.Spec.Version) if err == nil { falconContainer.Status.Sensor = common.ImageVersion(tag) } diff --git a/internal/controller/image/image_refresher.go b/internal/controller/image/image_refresher.go index d68eadf4..67344783 100644 --- a/internal/controller/image/image_refresher.go +++ b/internal/controller/image/image_refresher.go @@ -13,7 +13,6 @@ import ( "github.com/containers/image/v5/transports/alltransports" "github.com/containers/image/v5/types" - "github.com/crowdstrike/falcon-operator/pkg/common" "github.com/crowdstrike/falcon-operator/pkg/registry/auth" "github.com/crowdstrike/falcon-operator/pkg/registry/falcon_registry" "github.com/crowdstrike/gofalcon/falcon" @@ -37,7 +36,7 @@ func NewImageRefresher(ctx context.Context, log logr.Logger, falconConfig *falco } } -func (r *ImageRefresher) Refresh(imageDestination string, sensorType common.SensorType, versionRequested *string) (string, error) { +func (r *ImageRefresher) Refresh(imageDestination string, sensorType falcon.SensorType, versionRequested *string) (string, error) { falconTag, srcRef, sourceCtx, err := r.source(sensorType, versionRequested) if err != nil { return "", err @@ -96,7 +95,7 @@ func (r *ImageRefresher) Refresh(imageDestination string, sensorType common.Sens return falconTag, wrapWithHint(err) } -func (r *ImageRefresher) source(sensorType common.SensorType, versionRequested *string) (falconTag string, falconImage types.ImageReference, systemContext *types.SystemContext, err error) { +func (r *ImageRefresher) source(sensorType falcon.SensorType, versionRequested *string) (falconTag string, falconImage types.ImageReference, systemContext *types.SystemContext, err error) { registry, err := falcon_registry.NewFalconRegistry(r.ctx, r.falconConfig) if err != nil { return diff --git a/pkg/common/constants.go b/pkg/common/constants.go index 7e6820e8..12e27f90 100644 --- a/pkg/common/constants.go +++ b/pkg/common/constants.go @@ -1,13 +1,5 @@ package common -type SensorType string - -const ( - SensorTypeSidecar SensorType = "falcon-container" - SensorTypeKac SensorType = "falcon-kac" - SensorTypeNode SensorType = "falcon-sensor" -) - const ( FalconContainerInjection = "sensor.falcon-system.crowdstrike.com/injection" FalconContainerInjectorTLSName = "injector-tls" diff --git a/pkg/registry/falcon_registry/container.go b/pkg/registry/falcon_registry/container.go index 0dcdd271..b6edad14 100644 --- a/pkg/registry/falcon_registry/container.go +++ b/pkg/registry/falcon_registry/container.go @@ -4,10 +4,10 @@ import ( "context" "strings" - "github.com/crowdstrike/falcon-operator/pkg/common" + "github.com/crowdstrike/gofalcon/falcon" ) -func (reg *FalconRegistry) LastContainerTag(ctx context.Context, sensorType common.SensorType, versionRequested *string) (string, error) { +func (reg *FalconRegistry) LastContainerTag(ctx context.Context, sensorType falcon.SensorType, versionRequested *string) (string, error) { systemContext, err := reg.systemContext() if err != nil { return "", err @@ -20,6 +20,6 @@ func (reg *FalconRegistry) LastContainerTag(ctx context.Context, sensorType comm }) } -func (fr *FalconRegistry) imageUriContainer(sensorType common.SensorType) string { - return SensorImageURI(fr.falconCloud, sensorType) +func (fr *FalconRegistry) imageUriContainer(sensorType falcon.SensorType) string { + return falcon.FalconContainerSensorImageURI(fr.falconCloud, sensorType) } diff --git a/pkg/registry/falcon_registry/node.go b/pkg/registry/falcon_registry/node.go index 38e2c051..1c07eab5 100644 --- a/pkg/registry/falcon_registry/node.go +++ b/pkg/registry/falcon_registry/node.go @@ -2,7 +2,6 @@ package falcon_registry import ( "context" - "fmt" "strings" "github.com/crowdstrike/gofalcon/falcon" @@ -22,7 +21,7 @@ func (reg *FalconRegistry) LastNodeTag(ctx context.Context, versionRequested *st } func ImageURINode(falconCloud falcon.CloudType) string { - return fmt.Sprintf("%s/falcon-sensor/%s/release/falcon-sensor", registryFQDN(falconCloud), registryCloud(falconCloud)) + return falcon.FalconContainerSensorImageURI(falconCloud, falcon.NodeSensor) } func (fr *FalconRegistry) imageUriNode() string { diff --git a/pkg/registry/falcon_registry/registry.go b/pkg/registry/falcon_registry/registry.go index 69f85b1f..67915590 100644 --- a/pkg/registry/falcon_registry/registry.go +++ b/pkg/registry/falcon_registry/registry.go @@ -10,7 +10,6 @@ import ( "github.com/containers/image/v5/docker/reference" "github.com/containers/image/v5/types" - "github.com/crowdstrike/falcon-operator/pkg/common" "github.com/crowdstrike/falcon-operator/pkg/falcon_api" "github.com/crowdstrike/falcon-operator/pkg/registry/auth" "github.com/crowdstrike/gofalcon/falcon" @@ -22,17 +21,6 @@ type FalconRegistry struct { falconCID string } -func SensorImageURI(falconCloud falcon.CloudType, sensorType common.SensorType) string { - switch sensorType { - case "falcon-container": - return fmt.Sprintf("%s/falcon-container/%s/release/falcon-sensor", registryFQDN(falconCloud), registryCloud(falconCloud)) - case "falcon-kac": - return fmt.Sprintf("%s/falcon-kac/%s/release/falcon-kac", registryFQDN(falconCloud), registryCloud(falconCloud)) - default: - return fmt.Sprintf("%s/falcon-sensor/%s/release/falcon-sensor", registryFQDN(falconCloud), registryCloud(falconCloud)) - } -} - func NewFalconRegistry(ctx context.Context, apiCfg *falcon.ApiConfig) (*FalconRegistry, error) { apiCfg.Context = ctx client, err := falcon.NewClient(apiCfg) @@ -75,7 +63,7 @@ func (reg *FalconRegistry) Pulltoken() ([]byte, error) { return dockerfile, nil } -func (reg *FalconRegistry) PullInfo(ctx context.Context, sensorType common.SensorType, versionRequested *string) (falconTag string, falconImage types.ImageReference, systemContext *types.SystemContext, err error) { +func (reg *FalconRegistry) PullInfo(ctx context.Context, sensorType falcon.SensorType, versionRequested *string) (falconTag string, falconImage types.ImageReference, systemContext *types.SystemContext, err error) { systemContext, err = reg.systemContext() if err != nil { return @@ -165,12 +153,3 @@ func registryFQDN(cloud falcon.CloudType) string { return "registry.crowdstrike.com" } } - -func registryCloud(cloud falcon.CloudType) string { - switch cloud { - case falcon.CloudUsGov1: - return "govcloud" - default: - return cloud.String() - } -}