func newExternalDNSClusterRole()

in pkg/manifests/external_dns.go [382:417]


func newExternalDNSClusterRole(externalDnsConfig *ExternalDnsConfig) *rbacv1.ClusterRole {
	role := &rbacv1.ClusterRole{
		TypeMeta: metav1.TypeMeta{
			Kind:       "ClusterRole",
			APIVersion: "rbac.authorization.k8s.io/v1",
		},
		ObjectMeta: metav1.ObjectMeta{
			Name:   externalDnsConfig.resourceName,
			Labels: GetTopLevelLabels(),
		},
		Rules: []rbacv1.PolicyRule{
			{
				APIGroups: []string{""},
				Resources: []string{"endpoints", "pods", "services", "configmaps"},
				Verbs:     []string{"get", "watch", "list"},
			},
			{
				APIGroups: []string{""},
				Resources: []string{"nodes"},
				Verbs:     []string{"get", "watch", "list"},
			},
		},
	}

	// sort for fixture tests
	sortedRts := make([]ResourceType, 0, len(externalDnsConfig.resourceTypes))
	for resourceType := range externalDnsConfig.resourceTypes {
		sortedRts = append(sortedRts, resourceType)
	}
	sort.Slice(sortedRts, func(i, j int) bool { return sortedRts[i] < sortedRts[j] })
	for _, resourceType := range sortedRts {
		role.Rules = append(role.Rules, resourceType.generateRBACRules(externalDnsConfig)...)
	}

	return role
}