Skip to content

Commit

Permalink
[release-1.9] Fix labels for console plugin resources (#2438)
Browse files Browse the repository at this point in the history
* [release-1.9] Fix kubevirt-console-plugin labels

This is a manual cherry-pick of #2389

Signed-off-by: Oren Cohen <ocohen@redhat.com>

* Pin kubevirtci to 2307121202-6724dec

Signed-off-by: Oren Cohen <ocohen@redhat.com>

---------

Signed-off-by: Oren Cohen <ocohen@redhat.com>
Co-authored-by: Nahshon Unna Tsameret <60659093+nunnatsa@users.noreply.github.com>
  • Loading branch information
orenc1 and nunnatsa authored Jul 16, 2023
1 parent 4478e78 commit b7f94ec
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 83 deletions.
4 changes: 3 additions & 1 deletion cluster/kubevirtci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
# limitations under the License.

export KUBEVIRT_PROVIDER=${KUBEVIRT_PROVIDER:-'k8s-1.25'}
export KUBEVIRTCI_TAG=$(curl -L -Ss https://storage.googleapis.com/kubevirt-prow/release/kubevirt/kubevirtci/latest)
# TODO: pin to a specific kubevirtci tag due to an issue in latest. see: https://github.com/kubevirt/kubevirt/pull/10103#issuecomment-1637077797 for details
# export KUBEVIRTCI_TAG=$(curl -L -Ss https://storage.googleapis.com/kubevirt-prow/release/kubevirt/kubevirtci/latest)
export KUBEVIRTCI_TAG=2307121202-6724dec
KUBEVIRTCI_PATH="${PWD}/_kubevirtci"
KUBEVIRTCI_REPO='https://github.com/kubevirt/kubevirtci.git'

Expand Down
4 changes: 2 additions & 2 deletions controllers/hyperconverged/testUtils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,11 @@ func getBasicDeployment() *BasicExpected {
expectedVirtioWinRoleBinding := operands.NewVirtioWinCmReaderRoleBinding(hco)
res.virtioWinRoleBinding = expectedVirtioWinRoleBinding

expectedConsolePluginDeployment, err := operands.NewKvUiPluginDeplymnt(hco)
expectedConsolePluginDeployment, err := operands.NewKvUIPluginDeplymnt(hco)
ExpectWithOffset(1, err).ToNot(HaveOccurred())
res.consolePluginDeploy = expectedConsolePluginDeployment

expectedConsolePluginService := operands.NewKvUiPluginSvc(hco)
expectedConsolePluginService := operands.NewKvUIPluginSvc(hco)
res.consolePluginSvc = expectedConsolePluginService

expectedConsolePlugin := operands.NewKvConsolePlugin(hco)
Expand Down
67 changes: 30 additions & 37 deletions controllers/operands/kubevirtConsolePlugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,40 +27,39 @@ import (

const (
kvUIPluginName = "kubevirt-plugin"
kvUIPluginDeploymentName = "kubevirt-console-plugin"
kvUIPluginDeploymentName = string(hcoutil.AppComponentUIPlugin)
kvUIPluginSvcName = kvUIPluginDeploymentName + "-service"
kvUIPluginNameEnv = "UI_PLUGIN_NAME"
kvServingCertName = "plugin-serving-cert"
nginxConfigMapName = "nginx-conf"
)

// **** Kubevirt UI Plugin Deployment Handler ****
func newKvUiPluginDplymntHandler(_ log.Logger, Client client.Client, Scheme *runtime.Scheme, hc *hcov1beta1.HyperConverged) ([]Operand, error) {
kvUiPluginDeplymnt, err := NewKvUiPluginDeplymnt(hc)
func newKvUIPluginDeploymentHandler(_ log.Logger, Client client.Client, Scheme *runtime.Scheme, hc *hcov1beta1.HyperConverged) ([]Operand, error) {
kvUIPluginDeployment, err := NewKvUIPluginDeplymnt(hc)
if err != nil {
return nil, err
}
return []Operand{newDeploymentHandler(Client, Scheme, kvUiPluginDeplymnt)}, nil
return []Operand{newDeploymentHandler(Client, Scheme, kvUIPluginDeployment)}, nil
}

// **** nginx config map Handler ****
func newKvUiNginxCmHandler(_ log.Logger, Client client.Client, Scheme *runtime.Scheme, hc *hcov1beta1.HyperConverged) ([]Operand, error) {
kvUiNginxCm := NewKvUiNginxCm(hc)
func newKvUINginxCmHandler(_ log.Logger, Client client.Client, Scheme *runtime.Scheme, hc *hcov1beta1.HyperConverged) ([]Operand, error) {
kvUINginxCM := NewKVUINginxCM(hc)

return []Operand{newCmHandler(Client, Scheme, kvUiNginxCm)}, nil
return []Operand{newCmHandler(Client, Scheme, kvUINginxCM)}, nil
}

// **** Kubevirt UI Console Plugin Custom Resource Handler ****
func newKvUiPluginCRHandler(_ log.Logger, Client client.Client, Scheme *runtime.Scheme, hc *hcov1beta1.HyperConverged) ([]Operand, error) {
kvUiConsolePluginCR := NewKvConsolePlugin(hc)
func newKvUIPluginCRHandler(_ log.Logger, Client client.Client, Scheme *runtime.Scheme, hc *hcov1beta1.HyperConverged) ([]Operand, error) {
kvUIConsolePluginCR := NewKvConsolePlugin(hc)

return []Operand{newConsolePluginHandler(Client, Scheme, kvUiConsolePluginCR)}, nil
return []Operand{newConsolePluginHandler(Client, Scheme, kvUIConsolePluginCR)}, nil
}

func NewKvUiPluginDeplymnt(hc *hcov1beta1.HyperConverged) (*appsv1.Deployment, error) {
func NewKvUIPluginDeplymnt(hc *hcov1beta1.HyperConverged) (*appsv1.Deployment, error) {
// The env var was validated prior to handler creation
kvUiPluginImage, _ := os.LookupEnv(hcoutil.KvUiPluginImageEnvV)
labels := getLabels(hc, hcoutil.AppComponentDeployment)
kvUIPluginImage, _ := os.LookupEnv(hcoutil.KvUIPluginImageEnvV)
labels := getLabels(hc, hcoutil.AppComponentUIPlugin)

deployment := &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -86,7 +85,7 @@ func NewKvUiPluginDeplymnt(hc *hcov1beta1.HyperConverged) (*appsv1.Deployment, e
Containers: []corev1.Container{
{
Name: kvUIPluginDeploymentName,
Image: kvUiPluginImage,
Image: kvUIPluginImage,
ImagePullPolicy: corev1.PullIfNotPresent,
Resources: corev1.ResourceRequirements{
Requests: map[corev1.ResourceName]resource.Quantity{
Expand All @@ -95,7 +94,7 @@ func NewKvUiPluginDeplymnt(hc *hcov1beta1.HyperConverged) (*appsv1.Deployment, e
},
},
Ports: []corev1.ContainerPort{{
ContainerPort: hcoutil.UiPluginServerPort,
ContainerPort: hcoutil.UIPluginServerPort,
Protocol: corev1.ProtocolTCP,
}},
SecurityContext: components.GetStdContainerSecurityContext(),
Expand Down Expand Up @@ -163,26 +162,20 @@ func NewKvUiPluginDeplymnt(hc *hcov1beta1.HyperConverged) (*appsv1.Deployment, e
return deployment, nil
}

func NewKvUiPluginSvc(hc *hcov1beta1.HyperConverged) *corev1.Service {
func NewKvUIPluginSvc(hc *hcov1beta1.HyperConverged) *corev1.Service {
servicePorts := []corev1.ServicePort{
{Port: hcoutil.UiPluginServerPort, Name: kvUIPluginDeploymentName + "-port", Protocol: corev1.ProtocolTCP, TargetPort: intstr.IntOrString{Type: intstr.Int, IntVal: hcoutil.UiPluginServerPort}},
{Port: hcoutil.UIPluginServerPort, Name: kvUIPluginDeploymentName + "-port", Protocol: corev1.ProtocolTCP, TargetPort: intstr.IntOrString{Type: intstr.Int, IntVal: hcoutil.UIPluginServerPort}},
}
pluginName := kvUIPluginDeploymentName
val, ok := os.LookupEnv(kvUIPluginNameEnv)
if ok && val != "" {
pluginName = val
}
labelSelect := map[string]string{"app": pluginName}

spec := corev1.ServiceSpec{
Ports: servicePorts,
Selector: labelSelect,
Selector: map[string]string{hcoutil.AppLabelComponent: string(hcoutil.AppComponentUIPlugin)},
}

return &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: kvUIPluginSvcName,
Labels: getLabels(hc, hcoutil.AppComponentDeployment),
Labels: getLabels(hc, hcoutil.AppComponentUIPlugin),
Annotations: map[string]string{
"service.beta.openshift.io/serving-cert-secret-name": kvServingCertName,
},
Expand All @@ -206,13 +199,13 @@ http {
root /usr/share/nginx/html;
}
}
`, hcoutil.UiPluginServerPort)
`, hcoutil.UIPluginServerPort)

func NewKvUiNginxCm(hc *hcov1beta1.HyperConverged) *corev1.ConfigMap {
func NewKVUINginxCM(hc *hcov1beta1.HyperConverged) *corev1.ConfigMap {
return &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: nginxConfigMapName,
Labels: getLabels(hc, hcoutil.AppComponentDeployment),
Labels: getLabels(hc, hcoutil.AppComponentUIPlugin),
Namespace: hc.Namespace,
},
Data: map[string]string{
Expand All @@ -225,7 +218,7 @@ func NewKvConsolePlugin(hc *hcov1beta1.HyperConverged) *consolev1.ConsolePlugin
return &consolev1.ConsolePlugin{
ObjectMeta: metav1.ObjectMeta{
Name: kvUIPluginName,
Labels: getLabels(hc, hcoutil.AppComponentDeployment),
Labels: getLabels(hc, hcoutil.AppComponentUIPlugin),
},
Spec: consolev1.ConsolePluginSpec{
DisplayName: "Kubevirt Console Plugin",
Expand All @@ -234,7 +227,7 @@ func NewKvConsolePlugin(hc *hcov1beta1.HyperConverged) *consolev1.ConsolePlugin
Service: &consolev1.ConsolePluginService{
Name: kvUIPluginSvcName,
Namespace: hc.Namespace,
Port: hcoutil.UiPluginServerPort,
Port: hcoutil.UIPluginServerPort,
BasePath: "/",
},
},
Expand Down Expand Up @@ -324,12 +317,12 @@ func (h consoleHandler) ensure(req *common.HcoRequest) *EnsureResult {
return &EnsureResult{
Err: err,
}
} else {
return &EnsureResult{
Err: nil,
Updated: true,
UpgradeDone: true,
}
}

return &EnsureResult{
Err: nil,
Updated: true,
UpgradeDone: true,
}
}
return &EnsureResult{
Expand Down
Loading

0 comments on commit b7f94ec

Please sign in to comment.