Skip to content

Commit

Permalink
Merge pull request #406 from redhatrises/fix_falcon_import
Browse files Browse the repository at this point in the history
fix: consistently use falconv1alpha1 for falcon v1alpha1 imports
  • Loading branch information
redhatrises authored Jul 25, 2023
2 parents cac39c4 + 7e31092 commit 0216732
Show file tree
Hide file tree
Showing 20 changed files with 109 additions and 109 deletions.
14 changes: 7 additions & 7 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"

v1alpha1 "github.com/crowdstrike/falcon-operator/api/falcon/v1alpha1"
falconv1alpha1 "github.com/crowdstrike/falcon-operator/api/falcon/v1alpha1"
containercontroller "github.com/crowdstrike/falcon-operator/controllers/falcon_container"
nodecontroller "github.com/crowdstrike/falcon-operator/controllers/falcon_node"
"github.com/crowdstrike/falcon-operator/pkg/common"
Expand All @@ -51,7 +51,7 @@ func init() {
utilruntime.Must(imagev1.AddToScheme(scheme))
utilruntime.Must(securityv1.AddToScheme(scheme))

utilruntime.Must(v1alpha1.AddToScheme(scheme))
utilruntime.Must(falconv1alpha1.AddToScheme(scheme))
// +kubebuilder:scaffold:scheme
}

Expand Down Expand Up @@ -119,11 +119,11 @@ func main() {
Namespace: watchNamespace, // namespaced-scope when the value is not an empty string
NewCache: cache.BuilderWithOptions(cache.Options{
SelectorsByObject: cache.SelectorsByObject{
&v1alpha1.FalconContainer{}: {},
&corev1.Namespace{}: {},
&rbacv1.ClusterRoleBinding{}: {},
&corev1.ServiceAccount{}: {},
&imagev1.ImageStream{}: {},
&falconv1alpha1.FalconContainer{}: {},
&corev1.Namespace{}: {},
&rbacv1.ClusterRoleBinding{}: {},
&corev1.ServiceAccount{}: {},
&imagev1.ImageStream{}: {},
&corev1.Service{}: {
Label: labels.SelectorFromSet(labels.Set{common.FalconComponentKey: common.FalconSidecarSensor}),
},
Expand Down
12 changes: 6 additions & 6 deletions controllers/falcon_container/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strconv"
"strings"

"github.com/crowdstrike/falcon-operator/api/falcon/v1alpha1"
falconv1alpha1 "github.com/crowdstrike/falcon-operator/api/falcon/v1alpha1"
"github.com/crowdstrike/falcon-operator/internal/controller/assets"
"github.com/crowdstrike/falcon-operator/pkg/common"
"github.com/crowdstrike/falcon-operator/pkg/falcon_api"
Expand All @@ -18,15 +18,15 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
)

func (r *FalconContainerReconciler) reconcileRegistryCABundleConfigMap(ctx context.Context, log logr.Logger, falconContainer *v1alpha1.FalconContainer) (*corev1.ConfigMap, error) {
func (r *FalconContainerReconciler) reconcileRegistryCABundleConfigMap(ctx context.Context, log logr.Logger, falconContainer *falconv1alpha1.FalconContainer) (*corev1.ConfigMap, error) {
return r.reconcileGenericConfigMap(registryCABundleConfigMapName, r.newCABundleConfigMap, ctx, log, falconContainer)
}

func (r *FalconContainerReconciler) reconcileConfigMap(ctx context.Context, log logr.Logger, falconContainer *v1alpha1.FalconContainer) (*corev1.ConfigMap, error) {
func (r *FalconContainerReconciler) reconcileConfigMap(ctx context.Context, log logr.Logger, falconContainer *falconv1alpha1.FalconContainer) (*corev1.ConfigMap, error) {
return r.reconcileGenericConfigMap(injectorConfigMapName, r.newConfigMap, ctx, log, falconContainer)
}

func (r *FalconContainerReconciler) reconcileGenericConfigMap(name string, genFunc func(context.Context, logr.Logger, *v1alpha1.FalconContainer) (*corev1.ConfigMap, error), ctx context.Context, log logr.Logger, falconContainer *v1alpha1.FalconContainer) (*corev1.ConfigMap, error) {
func (r *FalconContainerReconciler) reconcileGenericConfigMap(name string, genFunc func(context.Context, logr.Logger, *falconv1alpha1.FalconContainer) (*corev1.ConfigMap, error), ctx context.Context, log logr.Logger, falconContainer *falconv1alpha1.FalconContainer) (*corev1.ConfigMap, error) {
configMap, err := genFunc(ctx, log, falconContainer)
if err != nil {
return configMap, fmt.Errorf("unable to render expected configmap: %v", err)
Expand All @@ -50,7 +50,7 @@ func (r *FalconContainerReconciler) reconcileGenericConfigMap(name string, genFu

}

func (r *FalconContainerReconciler) newCABundleConfigMap(ctx context.Context, log logr.Logger, falconContainer *v1alpha1.FalconContainer) (*corev1.ConfigMap, error) {
func (r *FalconContainerReconciler) newCABundleConfigMap(ctx context.Context, log logr.Logger, falconContainer *falconv1alpha1.FalconContainer) (*corev1.ConfigMap, error) {
data := make(map[string]string)
if falconContainer.Spec.Registry.TLS.CACertificate != "" {
data["tls.crt"] = string(common.DecodeBase64Interface(falconContainer.Spec.Registry.TLS.CACertificate))
Expand All @@ -60,7 +60,7 @@ func (r *FalconContainerReconciler) newCABundleConfigMap(ctx context.Context, lo
return &corev1.ConfigMap{}, fmt.Errorf("unable to determine contents of Registry TLS CACertificate attribute")
}

func (r *FalconContainerReconciler) newConfigMap(ctx context.Context, log logr.Logger, falconContainer *v1alpha1.FalconContainer) (*corev1.ConfigMap, error) {
func (r *FalconContainerReconciler) newConfigMap(ctx context.Context, log logr.Logger, falconContainer *falconv1alpha1.FalconContainer) (*corev1.ConfigMap, error) {
data := common.MakeSensorEnvMap(falconContainer.Spec.Falcon)
data["CP_NAMESPACE"] = r.Namespace()
data["FALCON_INJECTOR_LISTEN_PORT"] = strconv.Itoa(int(*falconContainer.Spec.Injector.ListenPort))
Expand Down
50 changes: 25 additions & 25 deletions controllers/falcon_container/falconcontainer_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"os"
"time"

"github.com/crowdstrike/falcon-operator/api/falcon/v1alpha1"
falconv1alpha1 "github.com/crowdstrike/falcon-operator/api/falcon/v1alpha1"
"github.com/crowdstrike/falcon-operator/version"
"github.com/go-logr/logr"
arv1 "k8s.io/api/admissionregistration/v1"
Expand Down Expand Up @@ -34,7 +34,7 @@ type FalconContainerReconciler struct {
// SetupWithManager sets up the controller with the Manager.
func (r *FalconContainerReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&v1alpha1.FalconContainer{}).
For(&falconv1alpha1.FalconContainer{}).
Owns(&appsv1.Deployment{}).
Owns(&corev1.Namespace{}).
Owns(&corev1.Secret{}).
Expand Down Expand Up @@ -69,7 +69,7 @@ func (r *FalconContainerReconciler) SetupWithManager(mgr ctrl.Manager) error {
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.7.2/pkg/reconcile
func (r *FalconContainerReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
log := log.FromContext(ctx)
falconContainer := &v1alpha1.FalconContainer{}
falconContainer := &falconv1alpha1.FalconContainer{}

if err := r.Get(ctx, req.NamespacedName, falconContainer); err != nil {
if errors.IsNotFound(err) {
Expand All @@ -83,9 +83,9 @@ func (r *FalconContainerReconciler) Reconcile(ctx context.Context, req ctrl.Requ
}

if falconContainer.Status.Conditions == nil || len(falconContainer.Status.Conditions) == 0 {
err := r.StatusUpdate(ctx, req, log, falconContainer, v1alpha1.ConditionPending,
err := r.StatusUpdate(ctx, req, log, falconContainer, falconv1alpha1.ConditionPending,
metav1.ConditionFalse,
v1alpha1.ReasonReqNotMet,
falconv1alpha1.ReasonReqNotMet,
"FalconContainer progressing")
if err != nil {
return ctrl.Result{}, err
Expand Down Expand Up @@ -116,18 +116,18 @@ func (r *FalconContainerReconciler) Reconcile(ctx context.Context, req ctrl.Requ
}
} else {
switch falconContainer.Spec.Registry.Type {
case v1alpha1.RegistryTypeECR:
case falconv1alpha1.RegistryTypeECR:
if _, err := r.UpsertECRRepo(ctx); err != nil {
err = r.StatusUpdate(ctx, req, log, falconContainer, v1alpha1.ConditionFailed, metav1.ConditionFalse, "Reconciling", fmt.Sprintf("failed to reconcile ECR repository: %v", err))
err = r.StatusUpdate(ctx, req, log, falconContainer, falconv1alpha1.ConditionFailed, metav1.ConditionFalse, "Reconciling", fmt.Sprintf("failed to reconcile ECR repository: %v", err))
if err != nil {
return ctrl.Result{}, err
}
return ctrl.Result{}, fmt.Errorf("failed to reconcile ECR repository: %v", err)
}
case v1alpha1.RegistryTypeOpenshift:
case falconv1alpha1.RegistryTypeOpenshift:
stream, err := r.reconcileImageStream(ctx, log, falconContainer)
if err != nil {
err = r.StatusUpdate(ctx, req, log, falconContainer, v1alpha1.ConditionFailed, metav1.ConditionFalse, "Reconciling", fmt.Sprintf("failed to reconcile Image Stream: %v", err))
err = r.StatusUpdate(ctx, req, log, falconContainer, falconv1alpha1.ConditionFailed, metav1.ConditionFalse, "Reconciling", fmt.Sprintf("failed to reconcile Image Stream: %v", err))
if err != nil {
return ctrl.Result{}, err
}
Expand All @@ -141,7 +141,7 @@ func (r *FalconContainerReconciler) Reconcile(ctx context.Context, req ctrl.Requ
// Create a CA Bundle ConfigMap if CACertificate attribute is set; overridden by the presence of a CACertificateConfigMap value
if falconContainer.Spec.Registry.TLS.CACertificateConfigMap == "" && falconContainer.Spec.Registry.TLS.CACertificate != "" {
if _, err := r.reconcileRegistryCABundleConfigMap(ctx, log, falconContainer); err != nil {
err = r.StatusUpdate(ctx, req, log, falconContainer, v1alpha1.ConditionFailed, metav1.ConditionFalse, "Reconciling", fmt.Sprintf("failed to reconcile Registry CA Certificate Bundle ConfigMap: %v", err))
err = r.StatusUpdate(ctx, req, log, falconContainer, falconv1alpha1.ConditionFailed, metav1.ConditionFalse, "Reconciling", fmt.Sprintf("failed to reconcile Registry CA Certificate Bundle ConfigMap: %v", err))
if err != nil {
return ctrl.Result{}, err
}
Expand All @@ -151,7 +151,7 @@ func (r *FalconContainerReconciler) Reconcile(ctx context.Context, req ctrl.Requ

if r.imageMirroringEnabled(falconContainer) {
if err := r.PushImage(ctx, log, falconContainer); err != nil {
err = r.StatusUpdate(ctx, req, log, falconContainer, v1alpha1.ConditionFailed, metav1.ConditionFalse, "Reconciling", fmt.Sprintf("failed to refresh Falcon Container image: %v", err))
err = r.StatusUpdate(ctx, req, log, falconContainer, falconv1alpha1.ConditionFailed, metav1.ConditionFalse, "Reconciling", fmt.Sprintf("failed to refresh Falcon Container image: %v", err))
if err != nil {
return ctrl.Result{}, err
}
Expand All @@ -164,7 +164,7 @@ func (r *FalconContainerReconciler) Reconcile(ctx context.Context, req ctrl.Requ
}
if err != nil {
log.Error(err, "Failed to verify CrowdStrike Container Image Registry access")
err = r.StatusUpdate(ctx, req, log, falconContainer, v1alpha1.ConditionFailed, metav1.ConditionFalse, "Reconciling", fmt.Sprintf("failed to verify CrowdStrike Container Image Registry access: %v", err))
err = r.StatusUpdate(ctx, req, log, falconContainer, falconv1alpha1.ConditionFailed, metav1.ConditionFalse, "Reconciling", fmt.Sprintf("failed to verify CrowdStrike Container Image Registry access: %v", err))
if err != nil {
return ctrl.Result{}, err
}
Expand All @@ -173,7 +173,7 @@ func (r *FalconContainerReconciler) Reconcile(ctx context.Context, req ctrl.Requ
}

if _, err = r.reconcileRegistrySecrets(ctx, log, falconContainer); err != nil {
err = r.StatusUpdate(ctx, req, log, falconContainer, v1alpha1.ConditionFailed, metav1.ConditionFalse, "Reconciling", fmt.Sprintf("failed to reconcile Falcon registry pull token Secrets: %v", err))
err = r.StatusUpdate(ctx, req, log, falconContainer, falconv1alpha1.ConditionFailed, metav1.ConditionFalse, "Reconciling", fmt.Sprintf("failed to reconcile Falcon registry pull token Secrets: %v", err))
if err != nil {
return ctrl.Result{}, err
}
Expand All @@ -183,15 +183,15 @@ func (r *FalconContainerReconciler) Reconcile(ctx context.Context, req ctrl.Requ
}

if _, err := r.reconcileServiceAccount(ctx, log, falconContainer); err != nil {
err = r.StatusUpdate(ctx, req, log, falconContainer, v1alpha1.ConditionFailed, metav1.ConditionFalse, "Reconciling", fmt.Sprintf("failed to reconcile Service Account: %v", err))
err = r.StatusUpdate(ctx, req, log, falconContainer, falconv1alpha1.ConditionFailed, metav1.ConditionFalse, "Reconciling", fmt.Sprintf("failed to reconcile Service Account: %v", err))
if err != nil {
return ctrl.Result{}, err
}
return ctrl.Result{}, fmt.Errorf("failed to reconcile Service Account: %v", err)
}

if _, err := r.reconcileClusterRoleBinding(ctx, log, falconContainer); err != nil {
err = r.StatusUpdate(ctx, req, log, falconContainer, v1alpha1.ConditionFailed, metav1.ConditionFalse, "Reconciling", fmt.Sprintf("failed to reconcile Cluster Role Binding: %v", err))
err = r.StatusUpdate(ctx, req, log, falconContainer, falconv1alpha1.ConditionFailed, metav1.ConditionFalse, "Reconciling", fmt.Sprintf("failed to reconcile Cluster Role Binding: %v", err))
if err != nil {
return ctrl.Result{}, err
}
Expand All @@ -200,39 +200,39 @@ func (r *FalconContainerReconciler) Reconcile(ctx context.Context, req ctrl.Requ

injectorTLS, err := r.reconcileInjectorTLSSecret(ctx, log, falconContainer)
if err != nil {
err = r.StatusUpdate(ctx, req, log, falconContainer, v1alpha1.ConditionFailed, metav1.ConditionFalse, "Reconciling", fmt.Sprintf("failed to reconcile injector TLS Secret: %v", err))
err = r.StatusUpdate(ctx, req, log, falconContainer, falconv1alpha1.ConditionFailed, metav1.ConditionFalse, "Reconciling", fmt.Sprintf("failed to reconcile injector TLS Secret: %v", err))
if err != nil {
return ctrl.Result{}, err
}
return ctrl.Result{}, fmt.Errorf("failed to reconcile injector TLS Secret: %v", err)
}
caBundle := injectorTLS.Data["ca.crt"]
if caBundle == nil {
err = r.StatusUpdate(ctx, req, log, falconContainer, v1alpha1.ConditionFailed, metav1.ConditionFalse, "Reconciling", "CA bundle not present in injector TLS Secret")
err = r.StatusUpdate(ctx, req, log, falconContainer, falconv1alpha1.ConditionFailed, metav1.ConditionFalse, "Reconciling", "CA bundle not present in injector TLS Secret")
if err != nil {
return ctrl.Result{}, err
}
return ctrl.Result{}, fmt.Errorf("CA bundle not present in injector TLS Secret")
}

if _, err = r.reconcileConfigMap(ctx, log, falconContainer); err != nil {
err = r.StatusUpdate(ctx, req, log, falconContainer, v1alpha1.ConditionFailed, metav1.ConditionFalse, "Reconciling", fmt.Sprintf("failed to reconcile injector ConfigMap: %v", err))
err = r.StatusUpdate(ctx, req, log, falconContainer, falconv1alpha1.ConditionFailed, metav1.ConditionFalse, "Reconciling", fmt.Sprintf("failed to reconcile injector ConfigMap: %v", err))
if err != nil {
return ctrl.Result{}, err
}
return ctrl.Result{}, fmt.Errorf("failed to reconcile injector ConfigMap: %v", err)
}

if _, err = r.reconcileDeployment(ctx, log, falconContainer); err != nil {
err = r.StatusUpdate(ctx, req, log, falconContainer, v1alpha1.ConditionFailed, metav1.ConditionFalse, "Reconciling", fmt.Sprintf("failed to reconcile injector Deployment: %v", err))
err = r.StatusUpdate(ctx, req, log, falconContainer, falconv1alpha1.ConditionFailed, metav1.ConditionFalse, "Reconciling", fmt.Sprintf("failed to reconcile injector Deployment: %v", err))
if err != nil {
return ctrl.Result{}, err
}
return ctrl.Result{}, fmt.Errorf("failed to reconcile injector Deployment: %v", err)
}

if _, err = r.reconcileService(ctx, log, falconContainer); err != nil {
err = r.StatusUpdate(ctx, req, log, falconContainer, v1alpha1.ConditionFailed, metav1.ConditionFalse, "Reconciling", fmt.Sprintf("failed to reconcile injector Service: %v", err))
err = r.StatusUpdate(ctx, req, log, falconContainer, falconv1alpha1.ConditionFailed, metav1.ConditionFalse, "Reconciling", fmt.Sprintf("failed to reconcile injector Service: %v", err))
if err != nil {
return ctrl.Result{}, err
}
Expand All @@ -241,7 +241,7 @@ func (r *FalconContainerReconciler) Reconcile(ctx context.Context, req ctrl.Requ

pod, err := r.injectorPodReady(ctx, falconContainer)
if err != nil && err.Error() != "No Injector pod found in a Ready state" {
err = r.StatusUpdate(ctx, req, log, falconContainer, v1alpha1.ConditionFailed, metav1.ConditionFalse, "Reconciling", fmt.Sprintf("failed to find Ready injector pod: %v", err))
err = r.StatusUpdate(ctx, req, log, falconContainer, falconv1alpha1.ConditionFailed, metav1.ConditionFalse, "Reconciling", fmt.Sprintf("failed to find Ready injector pod: %v", err))
if err != nil {
return ctrl.Result{}, err
}
Expand All @@ -253,16 +253,16 @@ func (r *FalconContainerReconciler) Reconcile(ctx context.Context, req ctrl.Requ
}

if _, err = r.reconcileWebhook(ctx, log, falconContainer, caBundle); err != nil {
err = r.StatusUpdate(ctx, req, log, falconContainer, v1alpha1.ConditionFailed, metav1.ConditionFalse, "Reconciling", fmt.Sprintf("failed to reconcile injector MutatingWebhookConfiguration: %v", err))
err = r.StatusUpdate(ctx, req, log, falconContainer, falconv1alpha1.ConditionFailed, metav1.ConditionFalse, "Reconciling", fmt.Sprintf("failed to reconcile injector MutatingWebhookConfiguration: %v", err))
if err != nil {
return ctrl.Result{}, err
}
return ctrl.Result{}, fmt.Errorf("failed to reconcile injector MutatingWebhookConfiguration: %v", err)
}

err = r.StatusUpdate(ctx, req, log, falconContainer, v1alpha1.ConditionSuccess,
err = r.StatusUpdate(ctx, req, log, falconContainer, falconv1alpha1.ConditionSuccess,
metav1.ConditionTrue,
v1alpha1.ReasonInstallSucceeded,
falconv1alpha1.ReasonInstallSucceeded,
"FalconContainer installation completed")
if err != nil {
return ctrl.Result{}, err
Expand All @@ -271,7 +271,7 @@ func (r *FalconContainerReconciler) Reconcile(ctx context.Context, req ctrl.Requ
return ctrl.Result{}, nil
}

func (r *FalconContainerReconciler) StatusUpdate(ctx context.Context, req ctrl.Request, log logr.Logger, falconContainer *v1alpha1.FalconContainer, condType string, status metav1.ConditionStatus, reason string, message string) error {
func (r *FalconContainerReconciler) StatusUpdate(ctx context.Context, req ctrl.Request, log logr.Logger, falconContainer *falconv1alpha1.FalconContainer, condType string, status metav1.ConditionStatus, reason string, message string) error {
meta.SetStatusCondition(&falconContainer.Status.Conditions, metav1.Condition{
Status: status,
Reason: reason,
Expand Down
Loading

0 comments on commit 0216732

Please sign in to comment.