Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Use correct versions to access OLM APIs #2095

Merged
merged 1 commit into from
Mar 5, 2021
Merged
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
23 changes: 11 additions & 12 deletions pkg/util/olm/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (

runtime "sigs.k8s.io/controller-runtime/pkg/client"

"github.com/operator-framework/api/pkg/operators"
operatorsv1 "github.com/operator-framework/api/pkg/operators/v1"
operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"

"github.com/apache/camel-k/pkg/client"
Expand Down Expand Up @@ -91,7 +91,7 @@ func IsOperatorInstalled(ctx context.Context, client client.Client, namespace st

// HasPermissionToInstall checks if the current user/serviceaccount has the right permissions to install camel k via OLM
func HasPermissionToInstall(ctx context.Context, client client.Client, namespace string, global bool, options Options) (bool, error) {
if ok, err := kubernetes.CheckPermission(ctx, client, operators.GroupName, "clusterserviceversions", namespace, options.Package, "list"); err != nil {
if ok, err := kubernetes.CheckPermission(ctx, client, operatorsv1alpha1.GroupName, "clusterserviceversions", namespace, options.Package, "list"); err != nil {
return false, err
} else if !ok {
return false, nil
Expand All @@ -102,7 +102,7 @@ func HasPermissionToInstall(ctx context.Context, client client.Client, namespace
targetNamespace = options.GlobalNamespace
}

if ok, err := kubernetes.CheckPermission(ctx, client, operators.GroupName, "subscriptions", targetNamespace, options.Package, "create"); err != nil {
if ok, err := kubernetes.CheckPermission(ctx, client, operatorsv1alpha1.GroupName, "subscriptions", targetNamespace, options.Package, "create"); err != nil {
return false, err
} else if !ok {
return false, nil
Expand All @@ -115,18 +115,18 @@ func HasPermissionToInstall(ctx context.Context, client client.Client, namespace
}

if !global {
if ok, err := kubernetes.CheckPermission(ctx, client, operators.GroupName, "operatorgroups", namespace, options.Package, "list"); err != nil {
if ok, err := kubernetes.CheckPermission(ctx, client, operatorsv1.GroupName, "operatorgroups", namespace, options.Package, "list"); err != nil {
return false, err
} else if !ok {
return false, nil
}

group, err := findOperatorGroup(ctx, client, namespace, options)
group, err := findOperatorGroup(ctx, client, namespace)
if err != nil {
return false, err
}
if group == nil {
if ok, err := kubernetes.CheckPermission(ctx, client, operators.GroupName, "operatorgroups", namespace, options.Package, "create"); err != nil {
if ok, err := kubernetes.CheckPermission(ctx, client, operatorsv1.GroupName, "operatorgroups", namespace, options.Package, "create"); err != nil {
return false, err
} else if !ok {
return false, nil
Expand Down Expand Up @@ -173,17 +173,17 @@ func Install(ctx context.Context, client client.Client, namespace string, global
}

if !global {
group, err := findOperatorGroup(ctx, client, namespace, options)
group, err := findOperatorGroup(ctx, client, namespace)
if err != nil {
return false, err
}
if group == nil {
group = &operators.OperatorGroup{
group = &operatorsv1.OperatorGroup{
ObjectMeta: v1.ObjectMeta{
Namespace: namespace,
GenerateName: fmt.Sprintf("%s-", namespace),
},
Spec: operators.OperatorGroupSpec{
Spec: operatorsv1.OperatorGroupSpec{
TargetNamespaces: []string{namespace},
},
}
Expand Down Expand Up @@ -256,9 +256,8 @@ func findCSV(ctx context.Context, client client.Client, namespace string, option
return nil, nil
}

// nolint:unparam
func findOperatorGroup(ctx context.Context, client client.Client, namespace string, options Options) (*operators.OperatorGroup, error) {
opGroupList := operators.OperatorGroupList{}
func findOperatorGroup(ctx context.Context, client client.Client, namespace string) (*operatorsv1.OperatorGroup, error) {
opGroupList := operatorsv1.OperatorGroupList{}
if err := client.List(ctx, &opGroupList, runtime.InNamespace(namespace)); err != nil {
return nil, err
}
Expand Down