Skip to content

Commit

Permalink
Add sidecar for nextcloud cron jobs
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas Bigler <[email protected]>
  • Loading branch information
TheBigLee committed Jan 10, 2025
1 parent 25d65f1 commit 539612e
Showing 1 changed file with 76 additions and 1 deletion.
77 changes: 76 additions & 1 deletion pkg/comp-functions/functions/vshnnextcloud/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"sigs.k8s.io/yaml"
)

const (
Expand Down Expand Up @@ -382,18 +384,77 @@ func newRelease(ctx context.Context, svc *runtime.ServiceRuntime, comp *vshnv1.V
return nil, fmt.Errorf("cannot get observed release values: %w", err)
}

_, err = maintenance.SetReleaseVersion(ctx, comp.Spec.Parameters.Service.Version, values, observedValues, []string{"image", "tag"})
version, err := maintenance.SetReleaseVersion(ctx, comp.Spec.Parameters.Service.Version, values, observedValues, []string{"image", "tag"})
if err != nil {
return nil, fmt.Errorf("cannot set keycloak version for release: %w", err)
}

err = configureCronSidecar(values, version)
if err != nil {
return nil, fmt.Errorf("cannot set keycloak version for cron sidecar: %w", err)
}

release, err := common.NewRelease(ctx, svc, comp, values)

release.Spec.ForProvider.Chart.Name = "nextcloud"

return release, err
}

func configureCronSidecar(values map[string]interface{}, version string) error {
extraSidecarContainers := map[string]any{
"name": "cron",
"command": []string{
"/cron.sh",
},
"image": "nextcloud:" + version,
"volumeMounts": []map[string]any{
{
"mountPath": "/var/www",
"name": "nextcloud-data",
"subpath": "root",
},
{
"mountPath": "/var/www/html",
"name": "nextcloud-data",
"subPath": "html",
},
{
"mountPath": "/var/www/html/data",
"name": "nextcloud-data",
"subPath": "data",
},
{
"mountPath": "/var/www/html/config",
"name": "nextcloud-data",
"subPath": "config",
},
{
"mountPath": "/var/www/html/custom_apps",
"name": "nextcloud-data",
"subPath": "custom_apps",
},
{
"mountPath": "/var/www/tmp",
"name": "nextcloud-data",
"subPath": "tmp",
},
{
"mountPath": "/var/www/html/themes",
"name": "nextcloud-data",
"subPath": "themes",
},
},
}

stringSidecarContainers, err := toYAML(extraSidecarContainers)
if err != nil {
return fmt.Errorf("cannot parse extraSidecarContainers: %w", err)
}

return unstructured.SetNestedField(values, []string{stringSidecarContainers}, []string{"nextcloud", "extraSidecarContainers"}...)
}

func addApacheConfig(svc *runtime.ServiceRuntime, comp *vshnv1.VSHNNextcloud) error {

cm := &v1.ConfigMap{
Expand Down Expand Up @@ -441,3 +502,17 @@ func setBackgroundJobMaintenance(t vshnv1.TimeOfDay, nextcloudConfig string) str

return strings.Replace(nextcloudConfig, "%maintenance_value%", strconv.Itoa(backgroundJobHour), 1)
}

func validateFQDNs(fqdns []string) error {
for _, fqdn := range fqdns {
if !valid.IsDNSName(fqdn) {
return fmt.Errorf("FQDN %s is not a valid DNS name", fqdn)
}
}
return nil
}

func toYAML(obj any) (string, error) {
yamlBytes, err := yaml.Marshal(obj)
return string(yamlBytes), err
}

0 comments on commit 539612e

Please sign in to comment.