Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Commit

Permalink
change: if default storage class exists use 10Gi PVC for registry (#1985
Browse files Browse the repository at this point in the history
)

Signed-off-by: Thorsten Klein <tk@thklein.io>
  • Loading branch information
iwilltry42 committed Jul 28, 2023
1 parent e207b5e commit 6db89ac
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 9 deletions.
50 changes: 46 additions & 4 deletions pkg/imagesystem/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ import (
v1 "github.com/acorn-io/runtime/pkg/apis/internal.acorn.io/v1"
"github.com/acorn-io/runtime/pkg/config"
"github.com/acorn-io/runtime/pkg/system"
"github.com/acorn-io/runtime/pkg/volume"
"github.com/google/go-containerregistry/pkg/name"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
)

Expand Down Expand Up @@ -121,10 +124,49 @@ func GetRegistryObjects(ctx context.Context, c client.Reader) (result []client.O
return nil, err
}

result = append(result, registryDeployment(
system.ImagesNamespace,
system.DefaultImage(),
system.ResourceRequirementsFor(*cfg.RegistryMemory, *cfg.RegistryCPU))...)
volumeSource := corev1.VolumeSource{
EmptyDir: &corev1.EmptyDirVolumeSource{},
}

if sc, err := volume.FindDefaultStorageClass(ctx, c); err != nil {
return nil, err
} else if sc != "" {
volumeSource = corev1.VolumeSource{
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
ClaimName: system.RegistryName,
},
}

result = append(result,
&corev1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{
Name: system.RegistryName,
Namespace: system.ImagesNamespace,
Labels: map[string]string{
"app": system.RegistryName,
},
},
Spec: corev1.PersistentVolumeClaimSpec{
StorageClassName: &sc,
AccessModes: []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce},
Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceStorage: resource.MustParse(system.RegistryPVCSize),
},
},
},
},
)
}

result = append(result,
registryDeployment(
system.ImagesNamespace,
system.DefaultImage(),
system.ResourceRequirementsFor(*cfg.RegistryMemory, *cfg.RegistryCPU),
volumeSource,
)...,
)

return result, nil
}
Expand Down
8 changes: 3 additions & 5 deletions pkg/imagesystem/registrytemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func registryService(namespace string) []client.Object {
}
}

func registryDeployment(namespace, registryImage string, requirements corev1.ResourceRequirements) []client.Object {
func registryDeployment(namespace, registryImage string, requirements corev1.ResourceRequirements, volumeSource corev1.VolumeSource) []client.Object {
deployment := &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: system.RegistryName,
Expand Down Expand Up @@ -117,10 +117,8 @@ func registryDeployment(namespace, registryImage string, requirements corev1.Res
},
Volumes: []corev1.Volume{
{
VolumeSource: corev1.VolumeSource{
EmptyDir: &corev1.EmptyDirVolumeSource{},
},
Name: "registry",
VolumeSource: volumeSource,
Name: "registry",
},
},
Tolerations: []corev1.Toleration{
Expand Down
1 change: 1 addition & 0 deletions pkg/system/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const (

var (
RegistryName = "registry"
RegistryPVCSize = "10Gi"
RegistryPort = 5000
BuildKitName = "buildkitd"
ControllerName = "acorn-controller"
Expand Down
15 changes: 15 additions & 0 deletions pkg/volume/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,18 @@ func CopyVolumeDefaults(volumeRequest v1.VolumeRequest, volumeBinding v1.VolumeB

return volumeRequest
}

func FindDefaultStorageClass(ctx context.Context, c client.Reader) (string, error) {
storageClasses := &storagev1.StorageClassList{}
if err := c.List(ctx, storageClasses); err != nil {
return "", err
}

for _, sc := range storageClasses.Items {
if sc.Annotations[storage.IsDefaultStorageClassAnnotation] == "true" {
return sc.Name, nil
}
}

return "", nil
}

0 comments on commit 6db89ac

Please sign in to comment.