|
@@ -58,8 +58,9 @@ func NewDefaultComponentReconciler(client client.Client, scheme *runtime.Scheme,
|
|
|
func (r *DefaultComponentReconciler) ReconcileComponent(ctx context.Context, tmpl *v1alpha1.Template, variables map[string]string) ([]client.Object, error) {
|
|
func (r *DefaultComponentReconciler) ReconcileComponent(ctx context.Context, tmpl *v1alpha1.Template, variables map[string]string) ([]client.Object, error) {
|
|
|
r.component.Labels = r.ResourceLabels()
|
|
r.component.Labels = r.ResourceLabels()
|
|
|
tmplVars := map[string]string{
|
|
tmplVars := map[string]string{
|
|
|
- "metadata.name": r.ResourceName(""),
|
|
|
|
|
- "spec.runtime.port": fmt.Sprintf("%d", tmpl.Spec.Runtime.Port),
|
|
|
|
|
|
|
+ "metadata.name": r.ResourceName(""),
|
|
|
|
|
+ "metadata.namespace": r.component.GetNamespace(),
|
|
|
|
|
+ "spec.runtime.port": fmt.Sprintf("%d", tmpl.Spec.Runtime.Port),
|
|
|
}
|
|
}
|
|
|
maps.Copy(tmplVars, variables)
|
|
maps.Copy(tmplVars, variables)
|
|
|
maps.Copy(tmplVars, r.component.Spec.Variables)
|
|
maps.Copy(tmplVars, r.component.Spec.Variables)
|
|
@@ -158,6 +159,33 @@ func (r *DefaultComponentReconciler) ReconcileStorage(ctx context.Context, name,
|
|
|
return nil
|
|
return nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// ReconcileDynamicStorage creates a PVC bound by the cluster's default
|
|
|
|
|
+// StorageClass. Runtimes such as lambdagent need a writable volume owned by a
|
|
|
|
|
+// non-root UID, which the hostPath fallback above cannot provide.
|
|
|
|
|
+func (r *DefaultComponentReconciler) ReconcileDynamicStorage(ctx context.Context, name, size string) error {
|
|
|
|
|
+ pvc := &corev1.PersistentVolumeClaim{ObjectMeta: metav1.ObjectMeta{Name: r.ResourceName(name), Namespace: r.component.GetNamespace()}}
|
|
|
|
|
+ storage := resource.MustParse(size)
|
|
|
|
|
+ _, err := controllerutil.CreateOrUpdate(ctx, r.client, pvc, func() error {
|
|
|
|
|
+ if pvc.Labels == nil {
|
|
|
|
|
+ pvc.Labels = map[string]string{}
|
|
|
|
|
+ }
|
|
|
|
|
+ maps.Copy(pvc.Labels, r.ResourceLabels())
|
|
|
|
|
+ // StorageClass and volumeName are immutable after binding; only apply
|
|
|
|
|
+ // the provisioning spec when the PVC is first created.
|
|
|
|
|
+ if pvc.ResourceVersion == "" {
|
|
|
|
|
+ pvc.Spec.AccessModes = []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce}
|
|
|
|
|
+ pvc.Spec.VolumeName = ""
|
|
|
|
|
+ pvc.Spec.StorageClassName = nil
|
|
|
|
|
+ if pvc.Spec.Resources.Requests == nil {
|
|
|
|
|
+ pvc.Spec.Resources.Requests = corev1.ResourceList{}
|
|
|
|
|
+ }
|
|
|
|
|
+ pvc.Spec.Resources.Requests[corev1.ResourceStorage] = storage
|
|
|
|
|
+ }
|
|
|
|
|
+ return controllerutil.SetControllerReference(r.component, pvc, r.scheme)
|
|
|
|
|
+ })
|
|
|
|
|
+ return err
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
func (r *DefaultComponentReconciler) reconcilePersistentVolume(ctx context.Context, name, size string) (string, error) {
|
|
func (r *DefaultComponentReconciler) reconcilePersistentVolume(ctx context.Context, name, size string) (string, error) {
|
|
|
pvName := fmt.Sprintf("%s-%s", r.component.GetNamespace(), r.ResourceName(name))
|
|
pvName := fmt.Sprintf("%s-%s", r.component.GetNamespace(), r.ResourceName(name))
|
|
|
pv := &corev1.PersistentVolume{ObjectMeta: metav1.ObjectMeta{Name: pvName}}
|
|
pv := &corev1.PersistentVolume{ObjectMeta: metav1.ObjectMeta{Name: pvName}}
|