-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package testutils | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
|
||
"github.com/kyma-project/lifecycle-manager/api/v1beta2" | ||
"github.com/kyma-project/lifecycle-manager/pkg/util" | ||
) | ||
|
||
func UpdateChannelVersionIfMRMExists(ctx context.Context, clnt client.Client, | ||
moduleName, namespace, channel, version string, | ||
) error { | ||
mrm, err := GetModuleReleaseMeta(ctx, moduleName, namespace, clnt) | ||
if err != nil { | ||
if util.IsNotFound(err) { | ||
return nil | ||
} | ||
return fmt.Errorf("get module release meta: %w", err) | ||
} | ||
|
||
channelFound := false | ||
for i, ch := range mrm.Spec.Channels { | ||
if ch.Channel == channel { | ||
mrm.Spec.Channels[i].Version = version | ||
channelFound = true | ||
break | ||
} | ||
} | ||
|
||
if !channelFound { | ||
mrm.Spec.Channels = append(mrm.Spec.Channels, v1beta2.ChannelVersionAssignment{ | ||
Channel: channel, | ||
Version: version, | ||
}) | ||
} | ||
|
||
if err = clnt.Update(ctx, mrm); err != nil { | ||
return fmt.Errorf("update module release meta: %w", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func GetModuleReleaseMeta(ctx context.Context, moduleName, namespace string, | ||
clnt client.Client, | ||
) (*v1beta2.ModuleReleaseMeta, error) { | ||
mrm := &v1beta2.ModuleReleaseMeta{} | ||
|
||
err := clnt.Get(ctx, client.ObjectKey{ | ||
Namespace: namespace, | ||
Name: moduleName, | ||
}, mrm) | ||
if err != nil { | ||
return nil, fmt.Errorf("get kyma: %w", err) | ||
} | ||
return mrm, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters