-
Notifications
You must be signed in to change notification settings - Fork 115
/
publishingstrategies_cr.go
82 lines (77 loc) · 2.72 KB
/
publishingstrategies_cr.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package cloudingress
import (
"context"
"github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
cloudingress "github.com/openshift/cloud-ingress-operator/api/v1alpha1"
"github.com/openshift/cloud-ingress-operator/pkg/ingresscontroller"
viper "github.com/openshift/osde2e/pkg/common/concurrentviper"
"github.com/openshift/osde2e/pkg/common/config"
"github.com/openshift/osde2e/pkg/common/helper"
"github.com/openshift/osde2e/pkg/common/label"
"github.com/openshift/osde2e/pkg/common/providers/rosaprovider"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/rest"
)
var _ = ginkgo.Describe("[Suite: operators] "+TestPrefix, label.Operators, func() {
ginkgo.BeforeEach(func() {
if viper.GetBool(rosaprovider.STS) {
ginkgo.Skip("STS does not support CIO")
}
if viper.GetBool(config.Hypershift) {
ginkgo.Skip("Cloud Ingress Operator is not supported on HyperShift")
}
})
h := helper.New()
ginkgo.Context("publishingstrategies", func() {
ginkgo.It(
"dedicated admin should not be allowed to manage publishingstrategies CR",
func(ctx context.Context) {
h.Impersonate(rest.ImpersonationConfig{
UserName: "test-user@redhat.com",
Groups: []string{
"dedicated-admins",
},
})
defer func() {
h.Impersonate(rest.ImpersonationConfig{})
}()
ps := createPublishingstrategies("publishingstrategy-cr-test-1")
err := addPublishingstrategy(ctx, h, ps)
Expect(apierrors.IsForbidden(err)).To(BeTrue())
},
)
})
})
func createPublishingstrategies(name string) cloudingress.PublishingStrategy {
publishingstrategy := cloudingress.PublishingStrategy{
TypeMeta: metav1.TypeMeta{
Kind: "PublishingStrategy",
APIVersion: ingresscontroller.SchemeGroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: name,
},
Spec: cloudingress.PublishingStrategySpec{
DefaultAPIServerIngress: cloudingress.DefaultAPIServerIngress{},
ApplicationIngress: []cloudingress.ApplicationIngress{},
},
}
return publishingstrategy
}
func addPublishingstrategy(ctx context.Context, h *helper.H, publishingstrategy cloudingress.PublishingStrategy) error {
obj, err := runtime.DefaultUnstructuredConverter.ToUnstructured(publishingstrategy.DeepCopy())
if err != nil {
return err
}
unstructuredObj := unstructured.Unstructured{obj}
_, err = h.Dynamic().
Resource(schema.GroupVersionResource{Group: "cloudingress.managed.openshift.io", Version: "v1alpha1", Resource: "publishingstrategies"}).
Namespace(OperatorNamespace).
Create(ctx, &unstructuredObj, metav1.CreateOptions{})
return err
}