Skip to content

Commit

Permalink
lossless install strategy byte conversion + unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: David Vossel <[email protected]>
  • Loading branch information
davidvossel committed Feb 26, 2019
1 parent ba8fe36 commit 509e3ed
Show file tree
Hide file tree
Showing 9 changed files with 197 additions and 51 deletions.
3 changes: 1 addition & 2 deletions pkg/virt-operator/creation/components/crds.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ func newBlankCrd() *extv1beta1.CustomResourceDefinition {
},
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
virtv1.AppLabel: "",
virtv1.ManagedByLabel: virtv1.ManagedByLabelOperatorValue,
virtv1.AppLabel: "",
},
},
}
Expand Down
10 changes: 3 additions & 7 deletions pkg/virt-operator/creation/components/deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ func NewPrometheusService(namespace string) *corev1.Service {
Name: "kubevirt-prometheus-metrics",
Labels: map[string]string{
virtv1.AppLabel: "",
virtv1.ManagedByLabel: virtv1.ManagedByLabelOperatorValue,
"prometheus.kubevirt.io": "",
},
},
Expand Down Expand Up @@ -158,8 +157,7 @@ func NewApiServerService(namespace string) *corev1.Service {
Namespace: namespace,
Name: "virt-api",
Labels: map[string]string{
virtv1.AppLabel: "virt-api",
virtv1.ManagedByLabel: virtv1.ManagedByLabelOperatorValue,
virtv1.AppLabel: "virt-api",
},
},
Spec: corev1.ServiceSpec{
Expand Down Expand Up @@ -233,8 +231,7 @@ func newBaseDeployment(name string, namespace string, repository string, version
Namespace: namespace,
Name: name,
Labels: map[string]string{
virtv1.AppLabel: name,
virtv1.ManagedByLabel: virtv1.ManagedByLabelOperatorValue,
virtv1.AppLabel: name,
},
},
Spec: appsv1.DeploymentSpec{
Expand Down Expand Up @@ -376,8 +373,7 @@ func NewHandlerDaemonSet(namespace string, repository string, version string, pu
Namespace: namespace,
Name: "virt-handler",
Labels: map[string]string{
virtv1.AppLabel: "virt-handler",
virtv1.ManagedByLabel: virtv1.ManagedByLabelOperatorValue,
virtv1.AppLabel: "virt-handler",
},
},
Spec: appsv1.DaemonSetSpec{
Expand Down
18 changes: 6 additions & 12 deletions pkg/virt-operator/creation/rbac/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ func newApiServerServiceAccount(namespace string) *corev1.ServiceAccount {
Namespace: namespace,
Name: "kubevirt-apiserver",
Labels: map[string]string{
virtv1.AppLabel: "",
virtv1.ManagedByLabel: virtv1.ManagedByLabelOperatorValue,
virtv1.AppLabel: "",
},
},
}
Expand All @@ -159,8 +158,7 @@ func newApiServerClusterRole() *rbacv1.ClusterRole {
ObjectMeta: metav1.ObjectMeta{
Name: "kubevirt-apiserver",
Labels: map[string]string{
virtv1.AppLabel: "",
virtv1.ManagedByLabel: virtv1.ManagedByLabelOperatorValue,
virtv1.AppLabel: "",
},
},
Rules: []rbacv1.PolicyRule{
Expand Down Expand Up @@ -271,8 +269,7 @@ func newApiServerClusterRoleBinding(namespace string) *rbacv1.ClusterRoleBinding
ObjectMeta: metav1.ObjectMeta{
Name: "kubevirt-apiserver",
Labels: map[string]string{
virtv1.AppLabel: "",
virtv1.ManagedByLabel: virtv1.ManagedByLabelOperatorValue,
virtv1.AppLabel: "",
},
},
RoleRef: rbacv1.RoleRef{
Expand All @@ -299,8 +296,7 @@ func newApiServerAuthDelegatorClusterRoleBinding(namespace string) *rbacv1.Clust
ObjectMeta: metav1.ObjectMeta{
Name: "kubevirt-apiserver-auth-delegator",
Labels: map[string]string{
virtv1.AppLabel: "",
virtv1.ManagedByLabel: virtv1.ManagedByLabelOperatorValue,
virtv1.AppLabel: "",
},
},
RoleRef: rbacv1.RoleRef{
Expand Down Expand Up @@ -328,8 +324,7 @@ func newApiServerRole(namespace string) *rbacv1.Role {
Namespace: namespace,
Name: "kubevirt-apiserver",
Labels: map[string]string{
virtv1.AppLabel: "",
virtv1.ManagedByLabel: virtv1.ManagedByLabelOperatorValue,
virtv1.AppLabel: "",
},
},
Rules: []rbacv1.PolicyRule{
Expand Down Expand Up @@ -369,8 +364,7 @@ func newApiServerRoleBinding(namespace string) *rbacv1.RoleBinding {
Namespace: namespace,
Name: "kubevirt-apiserver",
Labels: map[string]string{
virtv1.AppLabel: "",
virtv1.ManagedByLabel: virtv1.ManagedByLabelOperatorValue,
virtv1.AppLabel: "",
},
},
RoleRef: rbacv1.RoleRef{
Expand Down
13 changes: 4 additions & 9 deletions pkg/virt-operator/creation/rbac/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ func newDefaultClusterRole() *rbacv1.ClusterRole {
Name: "kubevirt.io:default",
Labels: map[string]string{
virtv1.AppLabel: "",
virtv1.ManagedByLabel: virtv1.ManagedByLabelOperatorValue,
"kubernetes.io/bootstrapping": "rbac-defaults",
},
Annotations: map[string]string{
Expand Down Expand Up @@ -136,8 +135,7 @@ func newDefaultClusterRoleBinding() *rbacv1.ClusterRoleBinding {
ObjectMeta: metav1.ObjectMeta{
Name: "kubevirt.io:default",
Labels: map[string]string{
virtv1.AppLabel: "",
virtv1.ManagedByLabel: virtv1.ManagedByLabelOperatorValue,
virtv1.AppLabel: "",
},
Annotations: map[string]string{
"rbac.authorization.kubernetes.io/autoupdate": "true",
Expand Down Expand Up @@ -172,8 +170,7 @@ func newAdminClusterRole() *rbacv1.ClusterRole {
ObjectMeta: metav1.ObjectMeta{
Name: "kubevirt.io:admin",
Labels: map[string]string{
virtv1.AppLabel: "",
virtv1.ManagedByLabel: virtv1.ManagedByLabelOperatorValue,
virtv1.AppLabel: "",
"rbac.authorization.k8s.io/aggregate-to-admin": "true",
},
},
Expand Down Expand Up @@ -228,8 +225,7 @@ func newEditClusterRole() *rbacv1.ClusterRole {
ObjectMeta: metav1.ObjectMeta{
Name: "kubevirt.io:edit",
Labels: map[string]string{
virtv1.AppLabel: "",
virtv1.ManagedByLabel: virtv1.ManagedByLabelOperatorValue,
virtv1.AppLabel: "",
"rbac.authorization.k8s.io/aggregate-to-edit": "true",
},
},
Expand Down Expand Up @@ -284,8 +280,7 @@ func newViewClusterRole() *rbacv1.ClusterRole {
ObjectMeta: metav1.ObjectMeta{
Name: "kubevirt.io:view",
Labels: map[string]string{
virtv1.AppLabel: "",
virtv1.ManagedByLabel: virtv1.ManagedByLabelOperatorValue,
virtv1.AppLabel: "",
"rbac.authorization.k8s.io/aggregate-to-view": "true",
},
},
Expand Down
9 changes: 3 additions & 6 deletions pkg/virt-operator/creation/rbac/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ func newControllerServiceAccount(namespace string) *corev1.ServiceAccount {
Namespace: namespace,
Name: "kubevirt-controller",
Labels: map[string]string{
virtv1.AppLabel: "",
virtv1.ManagedByLabel: virtv1.ManagedByLabelOperatorValue,
virtv1.AppLabel: "",
},
},
}
Expand All @@ -123,8 +122,7 @@ func newControllerClusterRole() *rbacv1.ClusterRole {
ObjectMeta: metav1.ObjectMeta{
Name: "kubevirt-controller",
Labels: map[string]string{
virtv1.AppLabel: "",
virtv1.ManagedByLabel: virtv1.ManagedByLabelOperatorValue,
virtv1.AppLabel: "",
},
},
Rules: []rbacv1.PolicyRule{
Expand Down Expand Up @@ -229,8 +227,7 @@ func newControllerClusterRoleBinding(namespace string) *rbacv1.ClusterRoleBindin
ObjectMeta: metav1.ObjectMeta{
Name: "kubevirt-controller",
Labels: map[string]string{
virtv1.AppLabel: "",
virtv1.ManagedByLabel: virtv1.ManagedByLabelOperatorValue,
virtv1.AppLabel: "",
},
},
RoleRef: rbacv1.RoleRef{
Expand Down
15 changes: 5 additions & 10 deletions pkg/virt-operator/creation/rbac/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ func newHandlerServiceAccount(namespace string) *corev1.ServiceAccount {
Namespace: namespace,
Name: "kubevirt-handler",
Labels: map[string]string{
virtv1.AppLabel: "",
virtv1.ManagedByLabel: virtv1.ManagedByLabelOperatorValue,
virtv1.AppLabel: "",
},
},
}
Expand All @@ -154,8 +153,7 @@ func newHandlerClusterRole() *rbacv1.ClusterRole {
ObjectMeta: metav1.ObjectMeta{
Name: "kubevirt-handler",
Labels: map[string]string{
virtv1.AppLabel: "",
virtv1.ManagedByLabel: virtv1.ManagedByLabelOperatorValue,
virtv1.AppLabel: "",
},
},
Rules: []rbacv1.PolicyRule{
Expand Down Expand Up @@ -216,8 +214,7 @@ func newHandlerClusterRoleBinding(namespace string) *rbacv1.ClusterRoleBinding {
ObjectMeta: metav1.ObjectMeta{
Name: "kubevirt-handler",
Labels: map[string]string{
virtv1.AppLabel: "",
virtv1.ManagedByLabel: virtv1.ManagedByLabelOperatorValue,
virtv1.AppLabel: "",
},
},
RoleRef: rbacv1.RoleRef{
Expand Down Expand Up @@ -245,8 +242,7 @@ func newHandlerRole(namespace string) *rbacv1.Role {
Namespace: namespace,
Name: "kubevirt-handler",
Labels: map[string]string{
virtv1.AppLabel: "",
virtv1.ManagedByLabel: virtv1.ManagedByLabelOperatorValue,
virtv1.AppLabel: "",
},
},
Rules: []rbacv1.PolicyRule{
Expand Down Expand Up @@ -275,8 +271,7 @@ func newHandlerRoleBinding(namespace string) *rbacv1.RoleBinding {
Namespace: namespace,
Name: "kubevirt-handler",
Labels: map[string]string{
virtv1.AppLabel: "",
virtv1.ManagedByLabel: virtv1.ManagedByLabelOperatorValue,
virtv1.AppLabel: "",
},
},
RoleRef: rbacv1.RoleRef{
Expand Down
13 changes: 13 additions & 0 deletions pkg/virt-operator/install-strategy/install_strategy_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package installstrategy_test

import (
"testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

func TestInstallStrategy(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "InstallStrategy Suite")
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func NewInstallStrategyConfigMap(namespace string, imageTag string, imageRegistr
},
},
Data: map[string]string{
"manifests": string(DumpInstallStrategyToBytes(strategy)),
"manifests": string(dumpInstallStrategyToBytes(strategy)),
},
}
return configMap, nil
Expand Down Expand Up @@ -125,7 +125,7 @@ func DumpInstallStrategyToConfigMap(clientset kubecli.KubevirtClient) error {
return nil
}

func DumpInstallStrategyToBytes(strategy *InstallStrategy) []byte {
func dumpInstallStrategyToBytes(strategy *InstallStrategy) []byte {

var b bytes.Buffer
writer := bufio.NewWriter(&b)
Expand Down Expand Up @@ -252,7 +252,7 @@ func LoadInstallStrategyFromCache(stores util.Stores, namespace string, imageTag
return nil, fmt.Errorf("install strategy configmap %s does not contain 'manifests' key", configMap.Name)
}

strategy, err := LoadInstallStrategyFromBytes(data)
strategy, err := loadInstallStrategyFromBytes(data)
if err != nil {
return nil, err
}
Expand All @@ -267,11 +267,11 @@ func LoadInstallStrategyFromFile(filePath string) (*InstallStrategy, error) {
return nil, err
}

return LoadInstallStrategyFromBytes(string(b))
return loadInstallStrategyFromBytes(string(b))

}

func LoadInstallStrategyFromBytes(data string) (*InstallStrategy, error) {
func loadInstallStrategyFromBytes(data string) (*InstallStrategy, error) {
strategy := &InstallStrategy{}
entries := strings.Split(data, "---")

Expand Down
Loading

0 comments on commit 509e3ed

Please sign in to comment.