Skip to content

Commit

Permalink
feat: use gofalcon for registry config and sensor types
Browse files Browse the repository at this point in the history
  • Loading branch information
redhatrises committed Jan 11, 2024
1 parent 0cf59a4 commit 685007a
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 45 deletions.
6 changes: 3 additions & 3 deletions internal/controller/admission/image_push.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
6 changes: 3 additions & 3 deletions internal/controller/falcon_container/image_push.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
5 changes: 2 additions & 3 deletions internal/controller/image/image_refresher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 0 additions & 8 deletions pkg/common/constants.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
8 changes: 4 additions & 4 deletions pkg/registry/falcon_registry/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
3 changes: 1 addition & 2 deletions pkg/registry/falcon_registry/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package falcon_registry

import (
"context"
"fmt"
"strings"

"github.com/crowdstrike/gofalcon/falcon"
Expand All @@ -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 {
Expand Down
23 changes: 1 addition & 22 deletions pkg/registry/falcon_registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
}

0 comments on commit 685007a

Please sign in to comment.