Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
awgreene committed Mar 4, 2020
1 parent fa9b9c2 commit 186ce26
Show file tree
Hide file tree
Showing 4 changed files with 282 additions and 62 deletions.
2 changes: 2 additions & 0 deletions pkg/controller/operators/olm/apiservices.go
Expand Up @@ -3,6 +3,7 @@ package olm
import (
"errors"
"fmt"
"strconv"
"time"

log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -375,6 +376,7 @@ func getPort(desc v1alpha1.APIServiceDescription) corev1.ServicePort {
containerPort = int(desc.ContainerPort)
}
return corev1.ServicePort{
Name: strconv.Itoa(containerPort),
Port: int32(containerPort),
TargetPort: intstr.FromInt(containerPort),
}
Expand Down
33 changes: 17 additions & 16 deletions pkg/controller/operators/olm/operator_test.go
Expand Up @@ -1156,28 +1156,28 @@ func TestTransitionCSV(t *testing.T) {
apis("a1.v1.a1Kind"), nil),
},
clientObjs: []runtime.Object{addAnnotation(defaultOperatorGroup, v1.OperatorGroupProvidedAPIsAnnotationKey, "a1Kind.v1.a1")},
apis: []runtime.Object{apiService("a1", "v1", "v1-a1", namespace, "", validCAPEM, apiregistrationv1.ConditionTrue, ownerLabelFromCSV("csv1", namespace))},
apis: []runtime.Object{apiService("a1", "v1", "a1", namespace, "", validCAPEM, apiregistrationv1.ConditionTrue, ownerLabelFromCSV("csv1", namespace))},
objs: []runtime.Object{
withLabels(
deployment("a1", namespace, "sa", addAnnotations(defaultTemplateAnnotations, map[string]string{
OLMCAHashAnnotationKey: validCAHash,
})),
ownerLabelFromCSV("csv1", namespace),
),
withAnnotations(keyPairToTLSSecret("v1.a1-cert", namespace, signedServingPair(time.Now().Add(24*time.Hour), validCA, []string{"v1-a1.ns", "v1-a1.ns.svc"})), map[string]string{
withAnnotations(keyPairToTLSSecret("a1-cert", namespace, signedServingPair(time.Now().Add(24*time.Hour), validCA, []string{"a1.ns", "a1.ns.svc"})), map[string]string{
OLMCAHashAnnotationKey: validCAHash,
}),
service("v1-a1", namespace, "a1", 80),
service("a1", namespace, "a1", 80),
serviceAccount("sa", namespace),
role("v1.a1-cert", namespace, []rbacv1.PolicyRule{
role("a1-cert", namespace, []rbacv1.PolicyRule{
{
Verbs: []string{"get"},
APIGroups: []string{""},
Resources: []string{"secrets"},
ResourceNames: []string{"v1.a1-cert"},
ResourceNames: []string{"a1-cert"},
},
}),
roleBinding("v1.a1-cert", namespace, "v1.a1-cert", "sa", namespace),
roleBinding("a1-cert", namespace, "a1-cert", "sa", namespace),
role("extension-apiserver-authentication-reader", "kube-system", []rbacv1.PolicyRule{
{
Verbs: []string{"get"},
Expand All @@ -1186,7 +1186,7 @@ func TestTransitionCSV(t *testing.T) {
ResourceNames: []string{"extension-apiserver-authentication"},
},
}),
roleBinding("v1.a1-auth-reader", "kube-system", "extension-apiserver-authentication-reader", "sa", namespace),
roleBinding("a1-auth-reader", "kube-system", "extension-apiserver-authentication-reader", "sa", namespace),
clusterRole("system:auth-delegator", []rbacv1.PolicyRule{
{
Verbs: []string{"create"},
Expand All @@ -1199,7 +1199,7 @@ func TestTransitionCSV(t *testing.T) {
Resources: []string{"subjectaccessreviews"},
},
}),
clusterRoleBinding("v1.a1-system:auth-delegator", "system:auth-delegator", "sa", namespace),
clusterRoleBinding("a1-system:auth-delegator", "system:auth-delegator", "sa", namespace),
},
},
expected: expected{
Expand Down Expand Up @@ -1376,26 +1376,26 @@ func TestTransitionCSV(t *testing.T) {
},
clientObjs: []runtime.Object{defaultOperatorGroup},
apis: []runtime.Object{
apiService("a1", "v1", "v1-a1", namespace, "a1", validCAPEM, apiregistrationv1.ConditionTrue, ownerLabelFromCSV("csv1", namespace)),
apiService("a1", "v1", "a1", namespace, "a1", validCAPEM, apiregistrationv1.ConditionTrue, ownerLabelFromCSV("csv1", namespace)),
},
objs: []runtime.Object{
deployment("a1", namespace, "sa", addAnnotations(defaultTemplateAnnotations, map[string]string{
OLMCAHashAnnotationKey: validCAHash,
})),
withAnnotations(keyPairToTLSSecret("v1.a1-cert", namespace, signedServingPair(time.Now().Add(24*time.Hour), validCA, []string{"v1-a1.ns", "v1-a1.ns.svc"})), map[string]string{
withAnnotations(keyPairToTLSSecret("a1-cert", namespace, signedServingPair(time.Now().Add(24*time.Hour), validCA, []string{"a1.ns", "a1.ns.svc"})), map[string]string{
OLMCAHashAnnotationKey: validCAHash,
}),
service("v1-a1", namespace, "a1", 80),
service("a1", namespace, "a1", 80),
serviceAccount("sa", namespace),
role("v1.a1-cert", namespace, []rbacv1.PolicyRule{
role("a1-cert", namespace, []rbacv1.PolicyRule{
{
Verbs: []string{"get"},
APIGroups: []string{""},
Resources: []string{"secrets"},
ResourceNames: []string{"v1.a1-cert"},
ResourceNames: []string{"a1-cert"},
},
}),
roleBinding("v1.a1-cert", namespace, "v1.a1-cert", "sa", namespace),
roleBinding("a1-cert", namespace, "a1-cert", "sa", namespace),
role("extension-apiserver-authentication-reader", "kube-system", []rbacv1.PolicyRule{
{
Verbs: []string{"get"},
Expand All @@ -1404,7 +1404,7 @@ func TestTransitionCSV(t *testing.T) {
ResourceNames: []string{"extension-apiserver-authentication"},
},
}),
roleBinding("v1.a1-auth-reader", "kube-system", "extension-apiserver-authentication-reader", "sa", namespace),
roleBinding("a1-auth-reader", "kube-system", "extension-apiserver-authentication-reader", "sa", namespace),
clusterRole("system:auth-delegator", []rbacv1.PolicyRule{
{
Verbs: []string{"create"},
Expand All @@ -1417,7 +1417,7 @@ func TestTransitionCSV(t *testing.T) {
Resources: []string{"subjectaccessreviews"},
},
}),
clusterRoleBinding("v1.a1-system:auth-delegator", "system:auth-delegator", "sa", namespace),
clusterRoleBinding("a1-system:auth-delegator", "system:auth-delegator", "sa", namespace),
},
crds: []runtime.Object{
crd("c1", "v1", "g1"),
Expand Down Expand Up @@ -2940,6 +2940,7 @@ func TestTransitionCSV(t *testing.T) {
csv, ok := outCSVMap[csvName]
require.Equal(t, ok, csvState.exists, "%s existence should be %t", csvName, csvState.exists)
if csvState.exists {
t.Logf("CSV:\n %v", csv)
require.EqualValues(t, string(csvState.phase), string(csv.Status.Phase), "%s had incorrect phase", csvName)
if csvState.reason != "" {
require.EqualValues(t, string(csvState.reason), string(csv.Status.Reason), "%s had incorrect condition reason", csvName)
Expand Down

0 comments on commit 186ce26

Please sign in to comment.