Skip to content
Merged
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: 11 additions & 16 deletions internal/component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import "fmt"
type Component int

const (
All Component = iota
Both Component = iota
All
Central
SecuredCluster
Operator
Expand All @@ -14,7 +15,9 @@ const (
func FromArgs(args []string) (Component, error) {
if len(args) > 0 {
switch args[0] {
case "both", "all":
case "both":
return Both, nil
case "all":
return All, nil
case "central":
return Central, nil
Expand All @@ -31,8 +34,10 @@ func FromArgs(args []string) (Component, error) {

func (c Component) String() string {
switch c {
case All:
case Both:
return "Central and Secured Cluster"
case All:
return "Central, Secured Cluster, and Operator"
Comment thread
AlexVulaj marked this conversation as resolved.
case Central:
return "Central"
case SecuredCluster:
Expand All @@ -45,27 +50,17 @@ func (c Component) String() string {
}

func (c Component) IncludesCentral() bool {
if c == SecuredCluster || c == Operator {
return false
}
return true
return c == Both || c == All || c == Central
}

func (c Component) IncludesSensor() bool {
if c == Central || c == Operator {
return false
}
return true
}

func (c Component) IncludesOperator() bool {
return c == Operator || c == All
return c == Both || c == All || c == SecuredCluster
}

func (c Component) IncludesOperatorExplicitly() bool {
return c == Operator
}

func (c Component) IncludesBothCentralAndSensor() bool {
return c == Central || c == SecuredCluster || c == All
return c == Both || c == All
}
10 changes: 1 addition & 9 deletions internal/deployer/deploy_via_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (d *Deployer) ensureOperatorDeployed(ctx context.Context) error {
return fmt.Errorf("failed to deploy operator via OLM: %w", err)
}
} else {
if err := d.deployOperator(ctx); err != nil {
if err := d.deployOperatorNonOLM(ctx); err != nil {
return fmt.Errorf("failed to deploy operator: %w", err)
}
}
Expand All @@ -100,10 +100,6 @@ func (d *Deployer) ensureOperatorDeployed(ctx context.Context) error {
func (d *Deployer) deployCentralOperator(ctx context.Context, resources, exposure string) error {
d.logger.Info("🚀 Deploying Central via Operator...")

if err := d.ensureOperatorDeployed(ctx); err != nil {
return err
}

if err := d.prepareNamespace(ctx, d.centralNamespace); err != nil {
return fmt.Errorf("failed to prepare namespace: %w", err)
}
Expand Down Expand Up @@ -604,10 +600,6 @@ func (d *Deployer) configureCentralEndpoint(ctx context.Context, exposure string
func (d *Deployer) deploySecuredClusterOperator(ctx context.Context, resources string) error {
d.logger.Info("🚀 Deploying SecuredCluster via Operator...")

if err := d.ensureOperatorDeployed(ctx); err != nil {
return err
}

if err := d.prepareNamespace(ctx, d.sensorNamespace); err != nil {
return fmt.Errorf("failed to prepare namespace: %w", err)
}
Expand Down
50 changes: 45 additions & 5 deletions internal/deployer/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"os/exec"
"strings"
"sync"
"time"

"github.com/fatih/color"
Expand Down Expand Up @@ -571,9 +572,19 @@ func (d *Deployer) Deploy(ctx context.Context, components component.Component, r

d.logger.Infof("Initiating deployment of %s", components)

if components.IncludesOperator() {
// If only deploying operator, use the operator-only flow
if components.IncludesOperatorExplicitly() {
return d.deployOperatorOnly(ctx)
}

// Deploy operator first if needed (unless using Helm)
// Operator is required for central/sensor deployments when not using Helm
if !d.useHelm {
if err := d.ensureOperatorDeployed(ctx); err != nil {
return fmt.Errorf("failed to deploy operator: %w", err)
}
}

if components.IncludesCentral() {
if err := d.deployCentral(ctx, resources, exposure); err != nil {
return fmt.Errorf("failed to deploy central: %w", err)
Expand Down Expand Up @@ -660,11 +671,40 @@ func (d *Deployer) Teardown(ctx context.Context, components component.Component)
return d.teardownCentral(ctx)
case component.SecuredCluster:
return d.teardownSecuredCluster(ctx)
case component.All:
if err := d.teardownSecuredCluster(ctx); err != nil {
d.logger.Warningf("Error tearing down secured cluster: %v", err)
case component.Both, component.All:
// Tear down components in parallel for better performance
var wg sync.WaitGroup
Comment thread
mclasmeier marked this conversation as resolved.

// Always tear down central and sensor
wg.Add(2)

go func() {
defer wg.Done()
if err := d.teardownSecuredCluster(ctx); err != nil {
d.logger.Warningf("Error tearing down secured cluster: %v", err)
}
}()

go func() {
defer wg.Done()
if err := d.teardownCentral(ctx); err != nil {
d.logger.Warningf("Error tearing down central: %v", err)
}
}()

// For 'all', also tear down the operator in parallel
if components == component.All {
wg.Add(1)
go func() {
defer wg.Done()
if err := d.teardownOperator(ctx); err != nil {
d.logger.Warningf("Error tearing down operator: %v", err)
}
}()
}
return d.teardownCentral(ctx)

wg.Wait()
return nil
default:
return fmt.Errorf("unknown component: %s", components)
}
Expand Down
19 changes: 17 additions & 2 deletions internal/deployer/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ const (
operatorDeploymentName = "rhacs-operator-controller-manager"
)

// deployOperator deploys the RHACS operator
func (d *Deployer) deployOperator(ctx context.Context) error {
// deployOperatorNonOLM deploys the RHACS operator without OLM
func (d *Deployer) deployOperatorNonOLM(ctx context.Context) error {
d.logger.Infof("Operator tag: %s", d.operatorTag)
if d.useKonflux {
if err := d.ensureKonfluxImageRewriting(ctx); err != nil {
Expand Down Expand Up @@ -396,6 +396,7 @@ metadata:
name: %s
labels:
name: %s
app.kubernetes.io/managed-by: roxie
Comment thread
AlexVulaj marked this conversation as resolved.
`, operatorNamespace, operatorNamespace)

_, err := d.runKubectl(ctx, KubectlOptions{
Expand Down Expand Up @@ -634,3 +635,17 @@ func (d *Deployer) teardownOperatorNonOLM(ctx context.Context) error {
d.logger.Success("✓ Non-OLM operator resources removed")
return nil
}

// teardownOperator removes the operator if it exists, detecting the deployment mode automatically.
func (d *Deployer) teardownOperator(ctx context.Context) error {
operatorExists, operatorMode := d.detectOperatorDeploymentMode(ctx)
if !operatorExists {
d.logger.Dim("No operator deployment found, skipping operator teardown")
return nil
}

if operatorMode == OperatorModeOLM {
return d.teardownOperatorOLM(ctx)
}
return d.teardownOperatorNonOLM(ctx)
}
Loading