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

chore: Update vm-console-proxy to v0.5.0 #916

Merged
merged 2 commits into from
Mar 13, 2024
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
6 changes: 6 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -438,3 +438,9 @@ rules:
- patch
- update
- watch
- apiGroups:
- token.kubevirt.io
resources:
- virtualmachines/vnc
verbs:
- get
6 changes: 6 additions & 0 deletions data/olm-catalog/ssp-operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,12 @@ spec:
- patch
- update
- watch
- apiGroups:
- token.kubevirt.io
resources:
- virtualmachines/vnc
verbs:
- get
serviceAccountName: ssp-operator
deployments:
- label:
Expand Down
16 changes: 10 additions & 6 deletions data/vm-console-proxy-bundle/vm-console-proxy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,20 @@ metadata:
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: vm-console-proxy
name: token.kubevirt.io:generate
rules:
- apiGroups:
- ""
- token.kubevirt.io
resources:
- pods
- virtualmachines/vnc
verbs:
- get
- list
- watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: vm-console-proxy
rules:
- apiGroups:
- kubevirt.io
resources:
Expand Down Expand Up @@ -152,7 +156,7 @@ spec:
- args: []
command:
- /console
image: quay.io/kubevirt/vm-console-proxy:v0.4.0
image: quay.io/kubevirt/vm-console-proxy:v0.5.0
imagePullPolicy: Always
name: console
ports:
Expand Down
2 changes: 1 addition & 1 deletion internal/operands/vm-console-proxy/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ package vm_console_proxy
// This file is updated by GitHub action defined in .github/workflows/release-vm-console-proxy.yaml

const (
defaultVmConsoleProxyImageTag = "v0.4.0"
defaultVmConsoleProxyImageTag = "v0.5.0"
defaultVmConsoleProxyImage = "quay.io/kubevirt/vm-console-proxy:" + defaultVmConsoleProxyImageTag
)
22 changes: 16 additions & 6 deletions internal/operands/vm-console-proxy/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const (
// +kubebuilder:rbac:groups=rbac.authorization.k8s.io,resources=roles;rolebindings,verbs=get;list;watch;create;update;delete;patch
// +kubebuilder:rbac:groups=authentication.k8s.io,resources=tokenreviews,verbs=create
// +kubebuilder:rbac:groups=authorization.k8s.io,resources=subjectaccessreviews,verbs=create
// +kubebuilder:rbac:groups=token.kubevirt.io,resources=virtualmachines/vnc,verbs=get

func init() {
utilruntime.Must(routev1.Install(common.Scheme))
Expand All @@ -69,7 +70,7 @@ func WatchTypes() []operands.WatchType {

type vmConsoleProxy struct {
serviceAccount *core.ServiceAccount
clusterRole *rbac.ClusterRole
clusterRoles []rbac.ClusterRole
clusterRoleBinding *rbac.ClusterRoleBinding
roleBinding *rbac.RoleBinding
service *core.Service
Expand All @@ -80,10 +81,10 @@ type vmConsoleProxy struct {

var _ operands.Operand = &vmConsoleProxy{}

func New(bundle *vm_console_proxy_bundle.Bundle) *vmConsoleProxy {
func New(bundle *vm_console_proxy_bundle.Bundle) operands.Operand {
return &vmConsoleProxy{
serviceAccount: bundle.ServiceAccount,
clusterRole: bundle.ClusterRole,
clusterRoles: bundle.ClusterRoles,
clusterRoleBinding: bundle.ClusterRoleBinding,
roleBinding: bundle.RoleBinding,
service: bundle.Service,
Expand Down Expand Up @@ -120,15 +121,21 @@ func (v *vmConsoleProxy) Reconcile(request *common.Request) ([]common.ReconcileR
return results, nil
}

reconcileResults, err := common.CollectResourceStatus(request,
reconcileFuncs := []common.ReconcileFunc{
reconcileServiceAccount(*v.serviceAccount.DeepCopy()),
reconcileClusterRole(*v.clusterRole.DeepCopy()),
}
for i := range v.clusterRoles {
reconcileFuncs = append(reconcileFuncs, reconcileClusterRole(*v.clusterRoles[i].DeepCopy()))
}
reconcileFuncs = append(reconcileFuncs,
reconcileClusterRoleBinding(*v.clusterRoleBinding.DeepCopy()),
reconcileRoleBinding(v.roleBinding.DeepCopy()),
reconcileConfigMap(*v.configMap.DeepCopy()),
reconcileService(*v.service.DeepCopy()),
reconcileDeployment(*v.deployment.DeepCopy()),
reconcileApiService(v.apiService.DeepCopy()))

reconcileResults, err := common.CollectResourceStatus(request, reconcileFuncs...)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -202,8 +209,11 @@ func (v *vmConsoleProxy) Cleanup(request *common.Request) ([]common.CleanupResul
}
objectsToDelete = append(objectsToDelete, deployments...)

for i := range v.clusterRoles {
objectsToDelete = append(objectsToDelete, v.clusterRoles[i].DeepCopy())
}

objectsToDelete = append(objectsToDelete,
v.clusterRole.DeepCopy(),
v.clusterRoleBinding.DeepCopy(),
v.roleBinding.DeepCopy(),
v.apiService.DeepCopy())
Expand Down
38 changes: 30 additions & 8 deletions internal/operands/vm-console-proxy/reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

ssp "kubevirt.io/ssp-operator/api/v1beta2"
"kubevirt.io/ssp-operator/internal/common"
"kubevirt.io/ssp-operator/internal/operands"
. "kubevirt.io/ssp-operator/internal/test-utils"
vm_console_proxy_bundle "kubevirt.io/ssp-operator/internal/vm-console-proxy-bundle"
)
Expand All @@ -52,7 +53,7 @@ var _ = Describe("VM Console Proxy Operand", func() {

var (
bundle *vm_console_proxy_bundle.Bundle
operand *vmConsoleProxy
operand operands.Operand
request common.Request
)

Expand All @@ -72,7 +73,9 @@ var _ = Describe("VM Console Proxy Operand", func() {
Expect(err).ToNot(HaveOccurred())

ExpectResourceExists(bundle.ServiceAccount, request)
ExpectResourceExists(bundle.ClusterRole, request)
for _, clusterRole := range bundle.ClusterRoles {
ExpectResourceExists(&clusterRole, request)
}
ExpectResourceExists(bundle.ClusterRoleBinding, request)
ExpectResourceExists(bundle.RoleBinding, request)
ExpectResourceExists(bundle.ConfigMap, request)
Expand Down Expand Up @@ -117,7 +120,9 @@ var _ = Describe("VM Console Proxy Operand", func() {
Expect(err).ToNot(HaveOccurred())

ExpectResourceExists(bundle.ServiceAccount, request)
ExpectResourceExists(bundle.ClusterRole, request)
for _, clusterRole := range bundle.ClusterRoles {
ExpectResourceExists(&clusterRole, request)
}
ExpectResourceExists(bundle.ClusterRoleBinding, request)
ExpectResourceExists(bundle.RoleBinding, request)
ExpectResourceExists(bundle.ConfigMap, request)
Expand All @@ -129,7 +134,9 @@ var _ = Describe("VM Console Proxy Operand", func() {
Expect(err).ToNot(HaveOccurred())

ExpectResourceNotExists(bundle.ServiceAccount, request)
ExpectResourceNotExists(bundle.ClusterRole, request)
for _, clusterRole := range bundle.ClusterRoles {
ExpectResourceNotExists(&clusterRole, request)
}
ExpectResourceNotExists(bundle.ClusterRoleBinding, request)
ExpectResourceNotExists(bundle.RoleBinding, request)
ExpectResourceNotExists(bundle.ConfigMap, request)
Expand Down Expand Up @@ -246,7 +253,9 @@ var _ = Describe("VM Console Proxy Operand", func() {
Expect(err).ToNot(HaveOccurred())

ExpectResourceExists(bundle.ServiceAccount, request)
ExpectResourceExists(bundle.ClusterRole, request)
for _, clusterRole := range bundle.ClusterRoles {
ExpectResourceExists(&clusterRole, request)
}
ExpectResourceExists(bundle.ClusterRoleBinding, request)
ExpectResourceExists(bundle.RoleBinding, request)
ExpectResourceExists(bundle.ConfigMap, request)
Expand All @@ -260,7 +269,9 @@ var _ = Describe("VM Console Proxy Operand", func() {
Expect(err).ToNot(HaveOccurred())

ExpectResourceNotExists(bundle.ServiceAccount, request)
ExpectResourceNotExists(bundle.ClusterRole, request)
for _, clusterRole := range bundle.ClusterRoles {
ExpectResourceNotExists(&clusterRole, request)
}
ExpectResourceNotExists(bundle.ClusterRoleBinding, request)
ExpectResourceNotExists(bundle.RoleBinding, request)
ExpectResourceNotExists(bundle.ConfigMap, request)
Expand Down Expand Up @@ -323,7 +334,7 @@ func getMockedTestBundle() *vm_console_proxy_bundle.Bundle {
Labels: map[string]string{"control-plane": "vm-console-proxy"},
},
},
ClusterRole: &rbac.ClusterRole{
ClusterRoles: []rbac.ClusterRole{{
ObjectMeta: metav1.ObjectMeta{
Name: clusterRoleName,
Namespace: namespace,
Expand All @@ -346,7 +357,18 @@ func getMockedTestBundle() *vm_console_proxy_bundle.Bundle {
Resources: []string{"subjectaccessreviews"},
Verbs: []string{"create"},
}},
},
}, {
ObjectMeta: metav1.ObjectMeta{
Name: "token-generate",
Namespace: namespace,
Labels: map[string]string{},
},
Rules: []rbac.PolicyRule{{
APIGroups: []string{"token.kubevirt.io"},
Resources: []string{"virtualmachines/vnc"},
Verbs: []string{"get"},
}},
}},
ClusterRoleBinding: &rbac.ClusterRoleBinding{
ObjectMeta: metav1.ObjectMeta{
Name: clusterRoleBindingName,
Expand Down
16 changes: 10 additions & 6 deletions internal/vm-console-proxy-bundle/bundle-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,20 @@ metadata:
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: vm-console-proxy
name: token.kubevirt.io:generate
rules:
- apiGroups:
- ""
- token.kubevirt.io
resources:
- pods
- virtualmachines/vnc
verbs:
- get
- list
- watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: vm-console-proxy
rules:
- apiGroups:
- kubevirt.io
resources:
Expand Down Expand Up @@ -152,7 +156,7 @@ spec:
- args: []
command:
- /console
image: quay.io/kubevirt/vm-console-proxy:v0.3.1
image: quay.io/kubevirt/vm-console-proxy:v0.5.0
imagePullPolicy: Always
name: console
ports:
Expand Down
11 changes: 7 additions & 4 deletions internal/vm-console-proxy-bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const (

type Bundle struct {
ServiceAccount *core.ServiceAccount
ClusterRole *rbac.ClusterRole
ClusterRoles []rbac.ClusterRole
ClusterRoleBinding *rbac.ClusterRoleBinding
RoleBinding *rbac.RoleBinding
Service *core.Service
Expand Down Expand Up @@ -83,7 +83,9 @@ func loadBundleFromBytes(data []byte) (*Bundle, error) {
case rbac.ServiceAccountKind:
destObj = &(bundle.ServiceAccount)
case clusterRoleKind:
destObj = &(bundle.ClusterRole)
// Add a dummy object to the slice, it will be filled later
bundle.ClusterRoles = append(bundle.ClusterRoles, rbac.ClusterRole{})
destObj = &(bundle.ClusterRoles[len(bundle.ClusterRoles)-1])
case clusterRoleBindingsKind:
destObj = &(bundle.ClusterRoleBinding)
case roleBindingKind:
Expand All @@ -102,7 +104,7 @@ func loadBundleFromBytes(data []byte) (*Bundle, error) {
return nil, fmt.Errorf("unsupported Kind found in vm-console-proxy bundle: %s", kind)
}

if !reflect.ValueOf(destObj).Elem().IsNil() {
if kind != clusterRoleKind && !reflect.ValueOf(destObj).Elem().IsNil() {
return nil, fmt.Errorf("duplicate Kind found in vm-console-proxy bundle: %s", kind)
}

Expand All @@ -118,7 +120,7 @@ func validateBundle(bundle *Bundle) error {
if bundle.ServiceAccount == nil {
missingFields = append(missingFields, "ServiceAccount")
}
if bundle.ClusterRole == nil {
if len(bundle.ClusterRoles) == 0 {
missingFields = append(missingFields, "ClusterRole")
}
if bundle.ClusterRoleBinding == nil {
Expand All @@ -142,5 +144,6 @@ func validateBundle(bundle *Bundle) error {
if len(missingFields) > 0 {
return fmt.Errorf("bundle is missing these objects: %v", missingFields)
}

return nil
}
2 changes: 1 addition & 1 deletion internal/vm-console-proxy-bundle/bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var _ = Describe("VM Console Proxy Bundle", func() {
bundle, err := ReadBundle("bundle-test.yaml")
Expect(err).ToNot(HaveOccurred())
Expect(bundle.ServiceAccount).ToNot(BeNil(), "service account should not be nil")
Expect(bundle.ClusterRole).ToNot(BeNil(), "cluster role should not be nil")
Expect(bundle.ClusterRoles).ToNot(BeEmpty(), "cluster role should not be nil")
Expect(bundle.ClusterRoleBinding).ToNot(BeNil(), "cluster role binding should not be nil")
Expect(bundle.RoleBinding).ToNot(BeNil(), "role binding should not be nil")
Expect(bundle.Service).ToNot(BeNil(), "service should not be nil")
Expand Down