-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow OperatorPolicy to create OLM subscriptions
Modified the controller logic such that the OperatorPolicy controller can create OLM subscriptions based on the policy spec. Currently, an OperatorGroup is created for each Subscription. Future implementation will support creating OperatorGroups based on installModes supported by the generated CSVs. ref: https://issues.redhat.com/browse/ACM-6597 Signed-off-by: Jason Zhang <jaszhang@redhat.com>
- Loading branch information
1 parent
406ccf7
commit de86a78
Showing
4 changed files
with
240 additions
and
8 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,87 @@ | ||
package controllers | ||
|
||
import ( | ||
"testing" | ||
|
||
operatorv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1" | ||
"github.com/stretchr/testify/assert" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
|
||
policyv1beta1 "open-cluster-management.io/config-policy-controller/api/v1beta1" | ||
) | ||
|
||
func TestBuildSubscription(t *testing.T) { | ||
testSubscription := new(operatorv1alpha1.Subscription) | ||
testPolicy := &policyv1beta1.OperatorPolicy{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "my-policy", | ||
Namespace: "default", | ||
}, | ||
Spec: policyv1beta1.OperatorPolicySpec{ | ||
Severity: "low", | ||
RemediationAction: "enforce", | ||
ComplianceType: "musthave", | ||
Subscription: policyv1beta1.SubscriptionSpec{ | ||
SubscriptionSpec: operatorv1alpha1.SubscriptionSpec{ | ||
Channel: "stable", | ||
Package: "my-operator", | ||
InstallPlanApproval: "Automatic", | ||
CatalogSource: "my-catalog", | ||
CatalogSourceNamespace: "my-ns", | ||
StartingCSV: "my-operator-v1", | ||
}, | ||
Namespace: "default", | ||
}, | ||
}, | ||
} | ||
desiredGVK := schema.GroupVersionKind{ | ||
Group: "operators.coreos.com", | ||
Version: "v1alpha1", | ||
Kind: "Subscription", | ||
} | ||
|
||
// Check values are correctly bootstrapped to the Subscription | ||
ret := buildSubscription(testPolicy, testSubscription) | ||
assert.Equal(t, ret.GetObjectKind().GroupVersionKind(), desiredGVK) | ||
assert.Equal(t, ret.ObjectMeta.Name, "my-operator") | ||
assert.Equal(t, ret.ObjectMeta.Namespace, "default") | ||
assert.Equal(t, ret.Spec, &testPolicy.Spec.Subscription.SubscriptionSpec) | ||
} | ||
|
||
func TestBuildOperatorGroup(t *testing.T) { | ||
testPolicy := &policyv1beta1.OperatorPolicy{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "my-policy", | ||
Namespace: "default", | ||
}, | ||
Spec: policyv1beta1.OperatorPolicySpec{ | ||
Severity: "low", | ||
RemediationAction: "enforce", | ||
ComplianceType: "musthave", | ||
Subscription: policyv1beta1.SubscriptionSpec{ | ||
SubscriptionSpec: operatorv1alpha1.SubscriptionSpec{ | ||
Channel: "stable", | ||
Package: "my-operator", | ||
InstallPlanApproval: "Automatic", | ||
CatalogSource: "my-catalog", | ||
CatalogSourceNamespace: "my-ns", | ||
StartingCSV: "my-operator-v1", | ||
}, | ||
Namespace: "default", | ||
}, | ||
}, | ||
} | ||
desiredGVK := schema.GroupVersionKind{ | ||
Group: "operators.coreos.com", | ||
Version: "v1", | ||
Kind: "OperatorGroup", | ||
} | ||
|
||
// Ensure OperatorGroup values are populated correctly | ||
ret := buildOperatorGroup(testPolicy) | ||
assert.Equal(t, ret.GetObjectKind().GroupVersionKind(), desiredGVK) | ||
assert.Equal(t, ret.ObjectMeta.GetName(), "my-operator-operator-group") | ||
assert.Equal(t, ret.ObjectMeta.GetNamespace(), "default") | ||
assert.Equal(t, ret.Spec.TargetNamespaces, []string{"*"}) | ||
} |
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