Skip to content

Commit

Permalink
split SourceCRs, use mount_mount instead of lable for user input, bet…
Browse files Browse the repository at this point in the history
…ter error handling and error msg with solutions
  • Loading branch information
pixelsoccupied committed Feb 25, 2022
1 parent 3335343 commit 6a833b2
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,6 @@ spec:
diskPartition:
- device: /dev/sda
partitions:
- label: var-imageregistry
- mount_point: /var/my/path
size: 102500
start: 344844
40 changes: 29 additions & 11 deletions ztp/siteconfig-generator/siteConfig/siteConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package siteConfig

import (
"fmt"
"path"
"reflect"
"strings"

Expand Down Expand Up @@ -236,32 +237,49 @@ type DiskPartition struct {
}

type Partitions struct {
Label string `yaml:"label"`
MountPoint string `yaml:"mount_point" `
Size int `yaml:"size"`
Start int `yaml:"start"`
MountFileName string `yaml:"-"`
MountPath string `yaml:"-"`
Label string `yaml:"-"`
}

func (prt *Partitions) UnmarshalYAML(unmarshal func(interface{}) error) error {
type PartitionsDefault Partitions
var defaults = PartitionsDefault{}
err := unmarshal(&defaults)

if defaults.Start < 25000 {
// 25000 min value, otherwise root partition is too small and the installation will fail
err = fmt.Errorf("start value too small. must be over 25000")
}

if defaults.Size <= 0 {
err = fmt.Errorf("choose an appropritate disk size. must be greater than 1")
}

// it's a required field
if defaults.MountPoint == "" {
err = fmt.Errorf("must provide a path for mount_point. e.g /var/path")
}
// ensure path is absolute
if !(path.IsAbs(defaults.MountPoint)) {
defaults.MountPoint = path.Join("/", defaults.MountPoint)
}
// https://docs.openshift.com/container-platform/4.9/installing/installing_bare_metal/installing-bare-metal.html#installation-user-infra-machines-advanced_vardisk_installing-bare-metal
if !(strings.HasPrefix(defaults.Label, "var")) {
defaults.Label = "var-" + defaults.Label
// starts at var
if !(strings.HasPrefix(defaults.MountPoint, "/var")) {
defaults.MountPoint = path.Join("/var", defaults.MountPoint)
} else {
// run a clean to ensure path is not malformed
defaults.MountPoint = path.Clean(defaults.MountPoint)
}

defaults.MountPath = "/" + strings.ReplaceAll(defaults.Label, "-", "/")
// generate label from path
defaults.Label = strings.ReplaceAll(defaults.MountPoint[1:], "/", "-")

// sensitive and depends on the filesystem.path
defaults.MountFileName = unit.UnitNamePathEscape(defaults.MountPath) + ".mount"

if defaults.Start < 25000 {
// 25000 min value, otherwise root partition is too small and the installation will fail
err = fmt.Errorf("start value too small. must be over 25000")
}
defaults.MountFileName = unit.UnitNamePathEscape(defaults.MountPoint) + ".mount"

*prt = Partitions(defaults)
return err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ spec:
diskPartition:
- device: /dev/sda
partitions:
- label: var-imageregistry
- mount_pointt: imageregistry
size: 102500
start: 344844
`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,3 @@ spec:
operator: In
values:
- ""
---

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: image-registry-pvc
namespace: openshift-image-registry
annotations:
ran.openshift.io/ztp-deploy-wave: "2"
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 100Gi
storageClassName: image-registry-sc
volumeMode: Filesystem
15 changes: 15 additions & 0 deletions ztp/source-crs/ImageRegistryPvc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: image-registry-pvc
namespace: openshift-image-registry
annotations:
ran.openshift.io/ztp-deploy-wave: "2"
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 100Gi
storageClassName: image-registry-sc
volumeMode: Filesystem
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ spec:
filesystems:
{{- range .DiskPartition }}
{{- range .Partitions }}
- path: {{ .MountPath }}
device: /dev/disk/by-partlabel{{ .MountPath }}
- path: {{ .MountPoint }}
device: /dev/disk/by-partlabel{{ .MountPoint }}
format: xfs
{{- end }}
{{- end }}
Expand All @@ -40,8 +40,8 @@ spec:
[Unit]
Before=local-fs.target
[Mount]
Where={{ .MountPath }}
What=/dev/disk/by-partlabel{{ .MountPath }}
Where={{ .MountPoint }}
What=/dev/disk/by-partlabel{{ .MountPoint }}
[Install]
WantedBy=local-fs.target
{{- end }}
Expand Down

0 comments on commit 6a833b2

Please sign in to comment.