Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-v0.18] feat: add deploy VM console proxy feature gate #633

Merged
merged 1 commit into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions api/v1beta2/ssp_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ type TektonTasks struct {
// FeatureGates defines feature gate for tto operator
type FeatureGates struct {
DeployTektonTaskResources bool `json:"deployTektonTaskResources,omitempty"`

DeployVmConsoleProxy bool `json:"deployVmConsoleProxy,omitempty"`
}

// DataImportCronTemplate defines the template type for DataImportCrons.
Expand Down
2 changes: 2 additions & 0 deletions config/crd/bases/ssp.kubevirt.io_ssps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3915,6 +3915,8 @@ spec:
properties:
deployTektonTaskResources:
type: boolean
deployVmConsoleProxy:
type: boolean
type: object
tektonPipelines:
description: TektonPipelines is the configuration of the tekton-pipelines
Expand Down
3 changes: 3 additions & 0 deletions config/samples/ssp_v1beta2_ssp.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
apiVersion: ssp.kubevirt.io/v1beta2
kind: SSP
metadata:
annotations:
ssp.kubevirt.io/vm-console-proxy-namespace: "kubevirt"
name: ssp-sample
namespace: kubevirt
spec:
Expand All @@ -10,6 +12,7 @@ spec:
replicas: 2
featureGates:
deployTektonTaskResources: true
deployVmConsoleProxy: true
tektonPipelines:
namespace: kubevirt
tektonTasks:
Expand Down
2 changes: 2 additions & 0 deletions data/crd/ssp.kubevirt.io_ssps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3916,6 +3916,8 @@ spec:
properties:
deployTektonTaskResources:
type: boolean
deployVmConsoleProxy:
type: boolean
type: object
tektonPipelines:
description: TektonPipelines is the configuration of the tekton-pipelines
Expand Down
6 changes: 5 additions & 1 deletion data/olm-catalog/ssp-operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ metadata:
"apiVersion": "ssp.kubevirt.io/v1beta2",
"kind": "SSP",
"metadata": {
"annotations": {
"ssp.kubevirt.io/vm-console-proxy-namespace": "kubevirt"
},
"name": "ssp-sample",
"namespace": "kubevirt"
},
Expand All @@ -17,7 +20,8 @@ metadata:
"namespace": "kubevirt"
},
"featureGates": {
"deployTektonTaskResources": true
"deployTektonTaskResources": true,
"deployVmConsoleProxy": true
},
"tektonPipelines": {
"namespace": "kubevirt"
Expand Down
16 changes: 1 addition & 15 deletions internal/operands/vm-console-proxy/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package vm_console_proxy
import (
"context"
"fmt"
"strconv"

routev1 "github.com/openshift/api/route/v1"
apps "k8s.io/api/apps/v1"
Expand All @@ -19,7 +18,6 @@ import (
)

const (
EnableAnnotation = "ssp.kubevirt.io/vm-console-proxy-enabled"
VmConsoleProxyNamespaceAnnotation = "ssp.kubevirt.io/vm-console-proxy-namespace"

operandName = "vm-console-proxy"
Expand Down Expand Up @@ -90,7 +88,7 @@ func (v *vmConsoleProxy) WatchClusterTypes() []operands.WatchType {
}

func (v *vmConsoleProxy) Reconcile(request *common.Request) ([]common.ReconcileResult, error) {
if !isEnabled(request) {
if request.Instance.Spec.FeatureGates == nil || !request.Instance.Spec.FeatureGates.DeployVmConsoleProxy {
cleanupResults, err := v.Cleanup(request)
if err != nil {
return nil, err
Expand Down Expand Up @@ -250,18 +248,6 @@ func reconcileRoute(serviceName string) common.ReconcileFunc {
}
}

func isEnabled(request *common.Request) bool {
if request.Instance.GetAnnotations() == nil {
return false
}
if enable, isFound := request.Instance.GetAnnotations()[EnableAnnotation]; isFound {
if isEnabled, err := strconv.ParseBool(enable); err == nil {
return isEnabled
}
}
return false
}

func getVmConsoleProxyNamespace(request *common.Request) string {
const defaultNamespace = "kubevirt"
if request.Instance.GetAnnotations() == nil {
Expand Down
11 changes: 8 additions & 3 deletions internal/operands/vm-console-proxy/reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ var _ = Describe("VM Console Proxy Operand", func() {
ExpectResourceExists(bundle.Deployment, request)
ExpectResourceExists(newRoute(namespace, serviceName), request)

delete(request.Instance.Annotations, EnableAnnotation)
request.Instance.Spec.FeatureGates.DeployVmConsoleProxy = false

_, err = operand.Reconcile(&request)
Expect(err).ToNot(HaveOccurred())
Expand Down Expand Up @@ -279,7 +279,8 @@ var _ = Describe("VM Console Proxy Operand", func() {
ExpectResourceExists(deployment, request)
ExpectResourceExists(route, request)

delete(request.Instance.Annotations, EnableAnnotation)
request.Instance.Spec.FeatureGates.DeployVmConsoleProxy = false

delete(request.Instance.Annotations, VmConsoleProxyNamespaceAnnotation)

_, err = operand.Reconcile(&request)
Expand Down Expand Up @@ -323,10 +324,14 @@ func getMockedRequest() common.Request {
Name: name,
Namespace: namespace,
Annotations: map[string]string{
EnableAnnotation: "true",
VmConsoleProxyNamespaceAnnotation: namespace,
},
},
Spec: ssp.SSPSpec{
FeatureGates: &ssp.FeatureGates{
DeployVmConsoleProxy: true,
},
},
},
Logger: log,
VersionCache: common.VersionCache{},
Expand Down
2 changes: 1 addition & 1 deletion tests/tests_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ func (s *newSspStrategy) Init() {
common.AppKubernetesComponentLabel: common.AppComponentSchedule.String(),
},
Annotations: map[string]string{
vm_console_proxy.EnableAnnotation: "true",
vm_console_proxy.VmConsoleProxyNamespaceAnnotation: s.GetVmConsoleProxyNamespace(),
},
},
Expand All @@ -135,6 +134,7 @@ func (s *newSspStrategy) Init() {
},
FeatureGates: &sspv1beta2.FeatureGates{
DeployTektonTaskResources: false,
DeployVmConsoleProxy: true,
},
},
}
Expand Down
41 changes: 5 additions & 36 deletions tests/vm_console_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ package tests

import (
"crypto/tls"
"fmt"
"io"
"net/http"
"net/url"
"reflect"
"strconv"
"time"

. "github.com/onsi/ginkgo/v2"
Expand All @@ -17,7 +15,6 @@ import (
apps "k8s.io/api/apps/v1"
core "k8s.io/api/core/v1"
rbac "k8s.io/api/rbac/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/utils/pointer"

Expand All @@ -39,15 +36,16 @@ var _ = Describe("VM Console Proxy Operand", func() {

BeforeEach(OncePerOrdered, func() {
strategy.SkipSspUpdateTestsIfNeeded()
namespace := strategy.GetVmConsoleProxyNamespace()

updateSsp(func(foundSsp *ssp.SSP) {
if foundSsp.Spec.FeatureGates == nil {
foundSsp.Spec.FeatureGates = &ssp.FeatureGates{}
}
if foundSsp.GetAnnotations() == nil {
foundSsp.Annotations = make(map[string]string)
}

namespace := strategy.GetVmConsoleProxyNamespace()

foundSsp.Annotations[vm_console_proxy.EnableAnnotation] = "true"
foundSsp.Spec.FeatureGates.DeployVmConsoleProxy = true
foundSsp.Annotations[vm_console_proxy.VmConsoleProxyNamespaceAnnotation] = namespace
})

Expand Down Expand Up @@ -133,40 +131,11 @@ var _ = Describe("VM Console Proxy Operand", func() {
},
}

// Waiting until the proxy deployment is created.
// This is a workaround, because the above updateSsp() function updates only annotations,
// which don't update the .metadata.generation field. So the waitUntilDeployed() call
// below succeeds immediately, and does not wait until proxy resources are created.
Eventually(func() error {
return apiClient.Get(ctx, deploymentResource.GetKey(), &apps.Deployment{})
}, env.ShortTimeout(), time.Second).Should(Succeed())

waitUntilDeployed()
})

AfterEach(OncePerOrdered, func() {
strategy.RevertToOriginalSspCr()

// Similar workaround as in BeforeEach().
originalSspProxyAnnotation := getSsp().Annotations[vm_console_proxy.EnableAnnotation]
if isEnabled, _ := strconv.ParseBool(originalSspProxyAnnotation); !isEnabled {
Eventually(func() error {
deployment := &apps.Deployment{}
err := apiClient.Get(ctx, deploymentResource.GetKey(), deployment)
if errors.IsNotFound(err) {
return nil
}
if err != nil {
return err
}
if !deployment.DeletionTimestamp.IsZero() {
return nil
}
return fmt.Errorf("the console proxy deployment is not being deleted")
}, env.ShortTimeout(), time.Second).Should(Succeed())
}

waitUntilDeployed()
})

Context("Resource creation", Ordered, func() {
Expand Down
2 changes: 2 additions & 0 deletions vendor/kubevirt.io/ssp-operator/api/v1beta2/ssp_types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading