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
2 changes: 1 addition & 1 deletion cmd/upgrade_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func (uc *UpgradeCommand) process(ctx context.Context, path config.UpgradePath)
logger.Infow("deploying operator version", "version", version.Name)

// Install artifact version
if err := uc.operator.UpgradeOperator(ctx, version.BundleVersion); err != nil {
if err := uc.operator.UpgradeOperator(ctx, version); err != nil {
return fmt.Errorf("failed to prepare operator: %v", err)
}

Expand Down
8 changes: 6 additions & 2 deletions pkg/operator/interface.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package operator

import "context"
import (
"context"

"github.com/AlaudaDevops/upgrade-test/pkg/config"
)

// OperatorInterface defines the interface for operator operations
type OperatorInterface interface {
// UpgradeOperator upgrades the operator to the given version
UpgradeOperator(ctx context.Context, version string) error
UpgradeOperator(ctx context.Context, version config.Version) error
}
8 changes: 4 additions & 4 deletions pkg/operator/local/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ func NewLocalOperator(options config.OperatorConfig) (*LocalOperator, error) {
}, nil
}

func (o *LocalOperator) UpgradeOperator(ctx context.Context, version string) error {
func (o *LocalOperator) UpgradeOperator(ctx context.Context, version config.Version) error {
log := logging.FromContext(ctx)

if o.command == "" {
o.command = "make deploy"
}

log.Infof("upgrading operator version: %s", version)
log.Infof("upgrading operator version: %s", version.Name)

if err := o.runDeployCommand(ctx, version); err != nil {
if err := o.runDeployCommand(ctx, version.BundleVersion); err != nil {
return fmt.Errorf("failed to run deploy command: %v", err)
}

log.Infof("operator version %s upgraded successfully", version)
log.Infof("operator version %s upgraded successfully", version.Name)
return nil
}

Expand Down
10 changes: 7 additions & 3 deletions pkg/operator/operatorhub/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,20 @@ func (o *Operator) GetResource(ctx context.Context, name, namespace string, gvr
return o.client.Resource(gvr).Namespace(namespace).Get(ctx, name, metav1.GetOptions{})
}

func (o *Operator) UpgradeOperator(ctx context.Context, version string) error {
func (o *Operator) UpgradeOperator(ctx context.Context, version config.Version) error {
// Install artifact version
av, err := o.InstallArtifactVersion(ctx, version)
av, err := o.InstallArtifactVersion(ctx, version.BundleVersion)
if err != nil {
return fmt.Errorf("failed to prepare operator: %v", err)
}

// Get CSV version from artifact version
csv, _, _ := unstructured.NestedString(av.Object, "status", "version")
if err := o.InstallSubscription(ctx, csv); err != nil {
channel := version.Channel
if channel == "" {
channel = "stable" // default fallback
}
if err := o.InstallSubscription(ctx, csv, channel); err != nil {
return fmt.Errorf("failed to install subscription: %v", err)
}

Expand Down
10 changes: 5 additions & 5 deletions pkg/operator/operatorhub/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"knative.dev/pkg/logging"
)

func (o *Operator) InstallSubscription(ctx context.Context, csv string) error {
func (o *Operator) InstallSubscription(ctx context.Context, csv string, channel string) error {
if csv == "" {
return fmt.Errorf("csv is empty")
}
Expand All @@ -31,8 +31,8 @@ func (o *Operator) InstallSubscription(ctx context.Context, csv string) error {
return fmt.Errorf("failed to delete old csv: %v", err)
}

log.Infow("creating subscription", "name", o.name, "namespace", o.namespace, "csv", csv)
_, err := o.createSubscription(ctx, o.name, o.namespace, csv)
log.Infow("creating subscription", "name", o.name, "namespace", o.namespace, "csv", csv, "channel", channel)
_, err := o.createSubscription(ctx, o.name, o.namespace, csv, channel)
if err != nil {
return fmt.Errorf("failed to create subscription: %v", err)
}
Expand Down Expand Up @@ -95,7 +95,7 @@ func (o *Operator) deleteResource(ctx context.Context, gvr schema.GroupVersionRe
return nil
}

func (o *Operator) createSubscription(ctx context.Context, name, namespace, csv string) (*unstructured.Unstructured, error) {
func (o *Operator) createSubscription(ctx context.Context, name, namespace, csv string, channel string) (*unstructured.Unstructured, error) {
log := logging.FromContext(ctx)

_, err := o.client.Resource(namespaceGVR).Create(ctx, &unstructured.Unstructured{
Expand Down Expand Up @@ -123,7 +123,7 @@ func (o *Operator) createSubscription(ctx context.Context, name, namespace, csv
},
},
"spec": map[string]interface{}{
"channel": "stable",
"channel": channel,
"installPlanApproval": "Manual",
"name": name,
"source": "platform",
Expand Down