Skip to content

Commit

Permalink
bug(seaweedfs): fix data path, add validation in e2e tests (#1346)
Browse files Browse the repository at this point in the history
* chore: remove commented out test code

* f

* f

* f

* f

* f
  • Loading branch information
emosbaugh authored Oct 20, 2024
1 parent a1c8b0f commit ff3e5f2
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 10 deletions.
3 changes: 1 addition & 2 deletions e2e/cluster/docker/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,9 @@ func (c *Cluster) WaitForReady() {
}

func (c *Cluster) Cleanup(envs ...map[string]string) {
// if c.t.Failed() {
c.generateSupportBundle(envs...)
c.copyPlaywrightReport()
//}

for _, node := range c.Nodes {
node.Destroy()
}
Expand Down
2 changes: 0 additions & 2 deletions e2e/cluster/lxd/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -989,10 +989,8 @@ func (c *Cluster) InstallTestDependenciesDebian(t *testing.T, node int, withProx
}

func (c *Cluster) Cleanup(envs ...map[string]string) {
// if c.T.Failed() {
c.generateSupportBundle(envs...)
c.copyPlaywrightReport()
// }
}

func (c *Cluster) SetupPlaywrightAndRunTest(testName string, args ...string) (string, string, error) {
Expand Down
5 changes: 5 additions & 0 deletions e2e/scripts/check-airgap-installation-state.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ main() {
kubectl get cm -n kotsadm kotsadm-application-metadata -o yaml
exit 1
fi

# if this is the current version
if echo "$version" | grep -E "^(dev|appver)-" ; then
validate_data_dirs
fi
}

main "$@"
5 changes: 5 additions & 0 deletions e2e/scripts/check-airgap-post-ha-state.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ main() {
kubectl get cm -n kotsadm kotsadm-application-metadata -o yaml
exit 1
fi

# if this is the current version
if echo "$version" | grep -E "^(dev|appver)-" ; then
validate_data_dirs
fi
}

main "$@"
5 changes: 5 additions & 0 deletions e2e/scripts/check-installation-state.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ main() {
kubectl get cm -n kotsadm kotsadm-application-metadata -o yaml
exit 1
fi

# if this is the current version
if echo "$version" | grep -E "^(dev|appver)-" ; then
validate_data_dirs
fi
}

main "$@"
5 changes: 5 additions & 0 deletions e2e/scripts/check-post-ha-state.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ main() {
kubectl get cm -n kotsadm kotsadm-application-metadata -o yaml
exit 1
fi

# if this is the current version
if echo "$version" | grep -E "^(dev|appver)-" ; then
validate_data_dirs
fi
}

main "$@"
2 changes: 2 additions & 0 deletions e2e/scripts/check-postupgrade-state.sh
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ main() {
echo "not all nodes are running k8s $k8s_version"
exit 1
fi

validate_data_dirs
}

main "$@"
64 changes: 64 additions & 0 deletions e2e/scripts/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,67 @@ maybe_install_curl() {
apt-get install -y curl
fi
}

validate_data_dirs() {
local expected_datadir="$EMBEDDED_CLUSTER_BASE_DIR"
local expected_k0sdatadir="$EMBEDDED_CLUSTER_BASE_DIR/k0s"
local expected_openebsdatadir="$EMBEDDED_CLUSTER_BASE_DIR/openebs-local"
if [ "$KUBECONFIG" = "/var/lib/k0s/pki/admin.conf" ]; then
expected_k0sdatadir=/var/lib/k0s
expected_openebsdatadir=/var/openebs
fi

local fail=0

if kubectl -n kube-system get charts k0s-addon-chart-openebs -oyaml >/dev/null 2>&1 ; then
echo "found openebs chart"

openebsdatadir=$(kubectl -n kube-system get charts k0s-addon-chart-openebs -oyaml | grep -v apiVersion | grep "basePath:" | awk '{print $2}')
if [ "$openebsdatadir" != "$expected_openebsdatadir" ]; then
echo "got unexpected openebsdatadir $openebsdatadir, want $expected_openebsdatadir"
kubectl -n kube-system get charts k0s-addon-chart-openebs -oyaml | grep -v apiVersion | grep "basePath:" -A5 -B5
fail=1
else
echo "validated openebsdatadir $openebsdatadir"
fi
else
echo "did not find openebs chart"
fi

if kubectl -n kube-system get charts k0s-addon-chart-seaweedfs -oyaml >/dev/null 2>&1 ; then
echo "found seaweedfs chart"

seaweefdatadir=$(kubectl -n kube-system get charts k0s-addon-chart-seaweedfs -oyaml| grep -v apiVersion | grep -m 1 "hostPathPrefix:" | awk '{print $2}')
if ! echo "$seaweefdatadir" | grep -qE "^$expected_datadir/seaweedfs/(ssd|storage)$" ; then
echo "got unexpected seaweefdatadir $seaweefdatadir, want $expected_datadir/seaweedfs/(ssd|storage)"
kubectl -n kube-system get charts k0s-addon-chart-seaweedfs -oyaml| grep -v apiVersion | grep -m 1 "hostPathPrefix:" -A5 -B5
fail=1
else
echo "validated seaweefdatadir $seaweefdatadir"
fi
else
echo "did not find seaweedfs chart"
fi

if kubectl -n kube-system get charts k0s-addon-chart-velero -oyaml >/dev/null 2>&1 ; then
echo "found velero chart"

velerodatadir=$(kubectl -n kube-system get charts k0s-addon-chart-velero -oyaml | grep -v apiVersion | grep "podVolumePath:" | awk '{print $2}')
if [ "$velerodatadir" != "$expected_k0sdatadir/kubelet/pods" ]; then
echo "got unexpected velerodatadir $velerodatadir, want $expected_openebsdatadir/kubelet/pods"
kubectl -n kube-system get charts k0s-addon-chart-velero -oyaml | grep -v apiVersion | grep "podVolumePath:" -A5 -B5
fail=1
else
echo "validated velerodatadir $velerodatadir"
fi
else
echo "did not find velero chart"
fi

if [ "$fail" -eq 1 ]; then
echo "data dir validation failed"
exit 1
else
echo "data dir validation succeeded"
fi
}
8 changes: 4 additions & 4 deletions operator/pkg/charts/charts.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,14 +281,14 @@ func updateInfraChartsFromInstall(in *v1beta1.Installation, clusterConfig *k0sv1
}

dataPath := filepath.Join(provider.EmbeddedClusterSeaweedfsSubDir(), "ssd")
newVals, err = helm.SetValue(newVals, "global.data.hostPathPrefix", dataPath)
newVals, err = helm.SetValue(newVals, "master.data.hostPathPrefix", dataPath)
if err != nil {
return nil, fmt.Errorf("set helm values seaweedfs.global.data.hostPathPrefix: %w", err)
return nil, fmt.Errorf("set helm values seaweedfs.master.data.hostPathPrefix: %w", err)
}
logsPath := filepath.Join(provider.EmbeddedClusterSeaweedfsSubDir(), "storage")
newVals, err = helm.SetValue(newVals, "global.logs.hostPathPrefix", logsPath)
newVals, err = helm.SetValue(newVals, "master.logs.hostPathPrefix", logsPath)
if err != nil {
return nil, fmt.Errorf("set helm values seaweedfs.global.logs.hostPathPrefix: %w", err)
return nil, fmt.Errorf("set helm values seaweedfs.master.logs.hostPathPrefix: %w", err)
}

charts[i].Values, err = helm.MarshalValues(newVals)
Expand Down
9 changes: 7 additions & 2 deletions pkg/kubeutils/kubeutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package kubeutils
import (
"context"
"fmt"
"regexp"
"sort"
"time"

Expand Down Expand Up @@ -263,11 +264,15 @@ func GetPreviousInstallation(ctx context.Context, cli client.Client, in *embedde
}

var (
Version115 = semver.MustParse("1.15.0")
version115 = semver.MustParse("1.15.0")
oldVersionSchemeRegex = regexp.MustCompile(`.*\+ec\.[0-9]+`)
)

func lessThanK0s115(ver *semver.Version) bool {
return ver.LessThan(Version115)
if oldVersionSchemeRegex.MatchString(ver.Original()) {
return true
}
return ver.LessThan(version115)
}

// MaybeOverrideInstallationDataDirs checks if the previous installation is less than 1.15.0 that
Expand Down
7 changes: 7 additions & 0 deletions pkg/kubeutils/kubeutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,13 @@ func Test_lessThanK0s115(t *testing.T) {
},
want: false,
},
{
name: "old version scheme",
args: args{
ver: semver.MustParse("1.28.7+ec.0"),
},
want: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit ff3e5f2

Please sign in to comment.