knative.dev/pkg@v0.0.0-20260602142205-ac97e43f6622/test/crd.go (about) 1 /* 2 Copyright 2019 The Knative Authors 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 // This file contains functions that construct boilerplate CRD definitions. 18 19 package test 20 21 import ( 22 corev1 "k8s.io/api/core/v1" 23 rbacv1 "k8s.io/api/rbac/v1" 24 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 25 ) 26 27 const ( 28 nginxPort = 80 29 nginxName = "nginx" 30 nginxImage = "nginx:1.7.9" 31 ) 32 33 // ServiceAccount returns ServiceAccount object in given namespace 34 func ServiceAccount(name, namespace string) *corev1.ServiceAccount { 35 return &corev1.ServiceAccount{ 36 ObjectMeta: metav1.ObjectMeta{ 37 Name: name, 38 Namespace: namespace, 39 }, 40 } 41 } 42 43 // ClusterRoleBinding returns ClusterRoleBinding for given subject and role 44 func ClusterRoleBinding(name string, namespace string, serviceAccount string, role string) *rbacv1.ClusterRoleBinding { 45 return &rbacv1.ClusterRoleBinding{ 46 ObjectMeta: metav1.ObjectMeta{ 47 Name: name, 48 }, 49 Subjects: []rbacv1.Subject{ 50 { 51 Kind: "ServiceAccount", 52 Name: serviceAccount, 53 Namespace: namespace, 54 }, 55 }, 56 RoleRef: rbacv1.RoleRef{ 57 Kind: "ClusterRole", 58 Name: role, 59 APIGroup: "rbac.authorization.k8s.io", 60 }, 61 } 62 } 63 64 // CoreV1ObjectReference returns a corev1.ObjectReference for the given name, kind and apiversion 65 func CoreV1ObjectReference(kind, apiversion, name string) *corev1.ObjectReference { 66 return &corev1.ObjectReference{ 67 Kind: kind, 68 APIVersion: apiversion, 69 Name: name, 70 } 71 } 72 73 // NginxPod returns nginx pod defined in given namespace 74 func NginxPod(namespace string) *corev1.Pod { 75 return &corev1.Pod{ 76 ObjectMeta: metav1.ObjectMeta{ 77 Name: nginxName, 78 Namespace: namespace, 79 Labels: map[string]string{"sidecar.istio.io/inject": "true"}, 80 }, 81 Spec: corev1.PodSpec{ 82 Containers: []corev1.Container{ 83 { 84 Name: nginxName, 85 Image: nginxImage, 86 Ports: []corev1.ContainerPort{ 87 { 88 ContainerPort: nginxPort, 89 }, 90 }, 91 }, 92 }, 93 }, 94 } 95 }