Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Collect license used to install cluster in support bundles #1601

20 changes: 20 additions & 0 deletions cmd/installer/cli/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@ func InstallCmd(ctx context.Context, name string) *cobra.Command {
return err
}

logrus.Debugf("copy license file to %s", dataDir)
if err := copyLicenseFileToDataDir(licenseFile, dataDir); err != nil {
// TODO: Do we need to report this error?
logrus.Warnf("unable to copy license file to %s: %v", dataDir, err)
}

opts := addonsApplierOpts{
assumeYes: assumeYes,
license: licenseFile,
Expand Down Expand Up @@ -934,3 +940,17 @@ func normalizeNoPromptToYes(f *pflag.FlagSet, name string) pflag.NormalizedName
}
return pflag.NormalizedName(name)
}

func copyLicenseFileToDataDir(licenseFile, dataDir string) error {
if licenseFile == "" {
return nil
}
licenseData, err := os.ReadFile(licenseFile)
if err != nil {
return fmt.Errorf("unable to read license file: %w", err)
}
if err := os.WriteFile(filepath.Join(dataDir, "license.yaml"), licenseData, 0400); err != nil {
return fmt.Errorf("unable to write license file: %w", err)
}
return nil
}
16 changes: 13 additions & 3 deletions e2e/scripts/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,16 @@ ensure_binary_copy() {
fi
}

ensure_license_in_data_dir() {
local expected_license_path="$EMBEDDED_CLUSTER_BASE_DIR/license.yaml"
if [ -e "$expected_license_path" ]; then
echo "license file exists in $expected_license_path"
else
echo "license file does not exists in $expected_license_path"
return 1
fi
}

ensure_node_config() {
if ! kubectl describe node | grep "controller-label" ; then
echo "Failed to find controller-label"
Expand Down Expand Up @@ -362,7 +372,7 @@ validate_data_dirs() {
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}')
openebsdatadir=$(kubectl -n kube-system get charts k0s-addon-chart-openebs -oyaml | grep -v apiVersion | grep "basePath:" | awk '{print $2}')
echo "found openebsdatadir $openebsdatadir, want $expected_openebsdatadir"
if [ "$openebsdatadir" != "$expected_openebsdatadir" ]; then
echo "got unexpected openebsdatadir $openebsdatadir, want $expected_openebsdatadir"
Expand All @@ -378,7 +388,7 @@ validate_data_dirs() {
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}')
seaweefdatadir=$(kubectl -n kube-system get charts k0s-addon-chart-seaweedfs -oyaml| grep -v apiVersion | grep -m 1 "hostPathPrefix:" | awk '{print $2}')
echo "found seaweefdatadir $seaweefdatadir, want $expected_datadir/seaweedfs/(ssd|storage)"
if ! echo "$seaweefdatadir" | grep -qE "^$expected_datadir/seaweedfs/(ssd|storage)$" ; then
echo "got unexpected seaweefdatadir $seaweefdatadir, want $expected_datadir/seaweedfs/(ssd|storage)"
Expand All @@ -394,7 +404,7 @@ validate_data_dirs() {
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}')
velerodatadir=$(kubectl -n kube-system get charts k0s-addon-chart-velero -oyaml | grep -v apiVersion | grep "podVolumePath:" | awk '{print $2}')
echo "found velerodatadir $velerodatadir, want $expected_k0sdatadir/kubelet/pods"
if [ "$velerodatadir" != "$expected_k0sdatadir/kubelet/pods" ]; then
echo "got unexpected velerodatadir $velerodatadir, want $expected_openebsdatadir/kubelet/pods"
Expand Down
4 changes: 4 additions & 0 deletions e2e/scripts/single-node-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ main() {

echo "all pods"
kubectl get pods -A

if ! ensure_license_in_data_dir; then
exit 1
fi
}

main "$@"
3 changes: 3 additions & 0 deletions pkg/goods/support/host-support-bundle.tmpl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,9 @@ spec:
collectorName: "localhost-ips"
command: "sh"
args: ["-c", "host localhost"]
- copy:
collectorName: embedded-cluster # Directory to copy license file to
path: {{ .DataDir }}/license.yaml
hostAnalyzers:
- ipv4Interfaces:
outcomes:
Expand Down
Loading