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

KubeVirt switch StorageClass config from annotation to DC #5569

Merged
merged 1 commit into from
Jan 18, 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
4 changes: 2 additions & 2 deletions modules/api/cmd/kubermatic-api/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -35018,7 +35018,7 @@
"KubeVirtInfraStorageClass": {
"type": "object",
"properties": {
"isDefautClass": {
"isDefaultClass": {
"description": "Optional: IsDefaultClass. If true, the created StorageClass in the tenant cluster will be annotated with:\nstorageclass.kubernetes.io/is-default-class : true\nIf missing or false, annotation will be:\nstorageclass.kubernetes.io/is-default-class : false",
"type": "boolean",
"x-go-name": "IsDefaultClass"
Expand Down Expand Up @@ -35091,7 +35091,7 @@
"x-go-name": "ImageCloningEnabled"
},
"infraStorageClasses": {
"description": "InfraStorageClasses is a list of storage classes from KubeVirt infra cluster that are used for\ninitialization of user cluster storage classes by the CSI driver kubevirt (hot pluggable disks)",
"description": "Deprecated: in favor of InfraStorageClasses.\nInfraStorageClasses is a list of storage classes from KubeVirt infra cluster that are used for\ninitialization of user cluster storage classes by the CSI driver kubevirt (hot pluggable disks)",
"type": "array",
"items": {
"type": "string"
Expand Down
2 changes: 1 addition & 1 deletion modules/api/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ replace github.com/ajeddeloh/go-json => github.com/coreos/go-json v0.0.0-2022081

require (
github.com/pkg/errors v0.9.1
k8c.io/kubermatic/v2 v2.21.1-0.20230118103444-ee611be4f351
k8c.io/kubermatic/v2 v2.21.1-0.20230118134347-8b64fdaea27c
)

require (
Expand Down
4 changes: 2 additions & 2 deletions modules/api/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1339,8 +1339,8 @@ honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
k8c.io/kubeone v1.5.4 h1:+OUuz7zdLlRC6HTNKi1fAIUYimmVFwcCzDOu6TiBx9Q=
k8c.io/kubeone v1.5.4/go.mod h1:xNlAertZO2iKVE8pL0Ruf/zjtM+EBeiZJtueuncyjxI=
k8c.io/kubermatic/v2 v2.21.1-0.20230118103444-ee611be4f351 h1:PkPVavxSp6aoNcMN+0dzbR6W3bp5pCGerc3KqezLTZ8=
k8c.io/kubermatic/v2 v2.21.1-0.20230118103444-ee611be4f351/go.mod h1:Y9vixzPlFiQd8pIjIqXWa7pLd+IX5tClavZNWbOJK/0=
k8c.io/kubermatic/v2 v2.21.1-0.20230118134347-8b64fdaea27c h1:qJn8OjkoVOty3DZp2kKrX9shOYmM8LU05Z+3rWZJp+4=
k8c.io/kubermatic/v2 v2.21.1-0.20230118134347-8b64fdaea27c/go.mod h1:Y9vixzPlFiQd8pIjIqXWa7pLd+IX5tClavZNWbOJK/0=
k8c.io/operating-system-manager v1.1.2-0.20221201183812-4f7c5a687353 h1:d9GuR+62IjJkhk8v3aGg3ewRQPN1TxWKhCVlk8ZaYKg=
k8c.io/operating-system-manager v1.1.2-0.20221201183812-4f7c5a687353/go.mod h1:NGru44utIUfEOCkX2FwlrR+lyEXB+x/DPqh5Eq+fd4A=
k8c.io/reconciler v0.3.1 h1:fZ8gFvrDxjsJ6jdKogZVX9Er980EDUYnVPuOna32d0k=
Expand Down
11 changes: 8 additions & 3 deletions modules/api/pkg/provider/cloud/kubevirt/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,17 @@ const (

type kubevirt struct {
secretKeySelector provider.SecretKeySelectorValueFunc
dc *kubermaticv1.DatacenterSpecKubevirt
}

func NewCloudProvider(secretKeyGetter provider.SecretKeySelectorValueFunc) provider.CloudProvider {
func NewCloudProvider(dc *kubermaticv1.Datacenter, secretKeyGetter provider.SecretKeySelectorValueFunc) (provider.CloudProvider, error) {
if dc.Spec.Kubevirt == nil {
return nil, errors.New("datacenter is not an KubeVirt datacenter")
}
return &kubevirt{
secretKeySelector: secretKeyGetter,
}
dc: dc.Spec.Kubevirt,
}, nil
}

var _ provider.CloudProvider = &kubevirt{}
Expand All @@ -55,7 +60,7 @@ func (k *kubevirt) DefaultCloudSpec(ctx context.Context, spec *kubermaticv1.Clou
return err
}

return updateInfraStorageClassesInfo(ctx, client, spec)
return updateInfraStorageClassesInfo(ctx, client, spec.Kubevirt, k.dc)
}

func (k *kubevirt) ValidateCloudSpec(ctx context.Context, spec kubermaticv1.CloudSpec) error {
Expand Down
27 changes: 14 additions & 13 deletions modules/api/pkg/provider/cloud/kubevirt/storage_class.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ import (
ctrlruntimeclient "sigs.k8s.io/controller-runtime/pkg/client"
)

const (
// InfraStorageClassAnnotation represents a storage class that should be initialized on user clusters.
infraStorageClassAnnotation = "kubevirt-initialization.k8c.io/initialize-sc"
)

type storageClassAnnotationFilter func(map[string]string) bool

// ListStorageClasses returns list of storage classes filtered by annotations.
Expand All @@ -50,19 +45,25 @@ func ListStorageClasses(ctx context.Context, client ctrlruntimeclient.Client, an
return res, nil
}

func updateInfraStorageClassesInfo(ctx context.Context, client ctrlruntimeclient.Client, spec *kubermaticv1.CloudSpec) error {
storageClassList, err := ListStorageClasses(ctx, client, func(m map[string]string) bool {
return m[infraStorageClassAnnotation] == "true"
})
func updateInfraStorageClassesInfo(ctx context.Context, client ctrlruntimeclient.Client, spec *kubermaticv1.KubevirtCloudSpec, dc *kubermaticv1.DatacenterSpecKubevirt) error {
infraStorageClassList, err := ListStorageClasses(ctx, client, nil)
if err != nil {
return err
}
existingStorageClassSet := sets.New(spec.Kubevirt.InfraStorageClasses...)
existingInfraStorageClassSet := sets.New[string]()
for _, isc := range infraStorageClassList {
existingInfraStorageClassSet.Insert(isc.Name)
}

for _, sc := range storageClassList {
if !existingStorageClassSet.Has(sc.Name) {
spec.Kubevirt.InfraStorageClasses = append(spec.Kubevirt.InfraStorageClasses, sc.Name)
// Cluster will contain a list with only the StorageClasses
// that are in the DC configuration and also exist in the infra KubeVirt cluster.
storageClasses := make([]kubermaticv1.KubeVirtInfraStorageClass, 0)
for _, sc := range dc.InfraStorageClasses {
// if StorageClass exists in infra, keep it
if existingInfraStorageClassSet.Has(sc.Name) {
storageClasses = append(storageClasses, sc)
}
}
spec.StorageClasses = storageClasses
return nil
}
2 changes: 1 addition & 1 deletion modules/api/pkg/provider/cloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func Provider(
return fake.NewCloudProvider(), nil
}
if datacenter.Spec.Kubevirt != nil {
return kubevirt.NewCloudProvider(secretKeyGetter), nil
return kubevirt.NewCloudProvider(datacenter, secretKeyGetter)
}
if datacenter.Spec.Alibaba != nil {
return alibaba.NewCloudProvider(datacenter, secretKeyGetter)
Expand Down

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

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