Some updates
Signed-off-by: Nikolai Rodionov <allanger@badhouseplants.net>
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -6,7 +6,7 @@
|
|||||||
*.dylib
|
*.dylib
|
||||||
bin/*
|
bin/*
|
||||||
Dockerfile.cross
|
Dockerfile.cross
|
||||||
|
image.tar
|
||||||
# Test binary, built with `go test -c`
|
# Test binary, built with `go test -c`
|
||||||
*.test
|
*.test
|
||||||
|
|
||||||
|
@@ -67,11 +67,11 @@ spec:
|
|||||||
imagePullPolicy: Never
|
imagePullPolicy: Never
|
||||||
name: manager
|
name: manager
|
||||||
ports: []
|
ports: []
|
||||||
securityContext:
|
#securityContext:
|
||||||
allowPrivilegeEscalation: false
|
# allowPrivilegeEscalation: false
|
||||||
capabilities:
|
# capabilities:
|
||||||
drop:
|
# drop:
|
||||||
- "ALL"
|
# - "ALL"
|
||||||
livenessProbe:
|
livenessProbe:
|
||||||
httpGet:
|
httpGet:
|
||||||
path: /healthz
|
path: /healthz
|
||||||
|
@@ -28,6 +28,7 @@ import (
|
|||||||
|
|
||||||
yahov1alpha1 "github.com/allanger/yaho/api/v1alpha1"
|
yahov1alpha1 "github.com/allanger/yaho/api/v1alpha1"
|
||||||
"github.com/allanger/yaho/internal/downloader"
|
"github.com/allanger/yaho/internal/downloader"
|
||||||
|
"github.com/allanger/yaho/internal/tools/helm"
|
||||||
k8serrors "k8s.io/apimachinery/pkg/api/errors"
|
k8serrors "k8s.io/apimachinery/pkg/api/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -78,9 +79,10 @@ func (r *HelmReleaseReconciler) Reconcile(ctx context.Context, req ctrl.Request)
|
|||||||
return reconcileResult, nil
|
return reconcileResult, nil
|
||||||
}
|
}
|
||||||
log.Info("Pulled a chart", "path", path)
|
log.Info("Pulled a chart", "path", path)
|
||||||
//path, err := downloader.PullChart(repository, chart, version)
|
helmlib := &helm.HelmLib{}
|
||||||
//if err != nil { return ... }
|
if err := helmlib.InstallChart(ctx, path, helmReleaseCR.Name, helmReleaseCR.Namespace); err != nil {
|
||||||
//err := helm.InstallOrUpdate(); if err != nil { return ...}
|
return reconcileResult, nil
|
||||||
|
}
|
||||||
|
|
||||||
return ctrl.Result{}, nil
|
return ctrl.Result{}, nil
|
||||||
}
|
}
|
||||||
|
@@ -6,12 +6,10 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"helm.sh/helm/pkg/chartutil"
|
|
||||||
"helm.sh/helm/pkg/engine"
|
|
||||||
"helm.sh/helm/v3/pkg/action"
|
"helm.sh/helm/v3/pkg/action"
|
||||||
|
"helm.sh/helm/v3/pkg/chart/loader"
|
||||||
"helm.sh/helm/v3/pkg/cli"
|
"helm.sh/helm/v3/pkg/cli"
|
||||||
"helm.sh/helm/v3/pkg/registry"
|
"helm.sh/helm/v3/pkg/registry"
|
||||||
"honnef.co/go/tools/go/loader"
|
|
||||||
"sigs.k8s.io/controller-runtime/pkg/log"
|
"sigs.k8s.io/controller-runtime/pkg/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -52,13 +50,16 @@ func (h *HelmLib) PullChart(ctx context.Context, repository, chart, version stri
|
|||||||
return "", fmt.Errorf("unknown repo kind: %s", prefix)
|
return "", fmt.Errorf("unknown repo kind: %s", prefix)
|
||||||
}
|
}
|
||||||
client.Settings = cl
|
client.Settings = cl
|
||||||
client.UntarDir = workdir
|
|
||||||
client.Version = version
|
client.Version = version
|
||||||
|
client.DestDir = workdir
|
||||||
path, err := client.Run(chartRemote)
|
path, err := client.Run(chartRemote)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Error(err, "An unexpected error occurred while fetching the chart", "chart", chartRemote)
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
return path, nil
|
log.Info("Path is", "path", path)
|
||||||
|
// there must be a better way, but I couldn't find it yet
|
||||||
|
return fmt.Sprintf("%s/%s-%s.tgz", workdir, chart, version), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HelmLib) InstallChart(ctx context.Context, path string, name, namespace string) error {
|
func (h *HelmLib) InstallChart(ctx context.Context, path string, name, namespace string) error {
|
||||||
@@ -67,25 +68,13 @@ func (h *HelmLib) InstallChart(ctx context.Context, path string, name, namespace
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
values := chartutil.Values{}
|
client := action.NewInstall(&action.Configuration{})
|
||||||
values["Values"] = nil
|
client.DryRun = true
|
||||||
values["Release"] = map[string]string{
|
release, err := client.RunWithContext(ctx, chartObj, nil)
|
||||||
"Name": name,
|
|
||||||
"Namespace": namespace,
|
|
||||||
}
|
|
||||||
values["Capabilities"] = map[string]map[string]string{
|
|
||||||
"KubeVersion": {
|
|
||||||
"Version": "v1.27.9",
|
|
||||||
"GitVersion": "v1.27.9",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
files, err := engine.Engine{Strict: false}.Render(chartObj, values)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for file, data := range files {
|
log.Info("Got a manifest", "manifest", release.Manifest)
|
||||||
log.Info("File is rendered", "data", file)
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -9,14 +9,14 @@ import (
|
|||||||
|
|
||||||
func TestPullChart(t *testing.T) {
|
func TestPullChart(t *testing.T) {
|
||||||
helmlib := &helm.HelmLib{}
|
helmlib := &helm.HelmLib{}
|
||||||
path, err := helmlib.PullChart("https://coredns.github.io/helm", "coredns", "1.42.0")
|
path, err := helmlib.PullChart(t.Context(), "https://coredns.github.io/helm", "coredns", "1.42.0")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, "test", path)
|
assert.Equal(t, "test", path)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPullChartOci(t *testing.T) {
|
func TestPullChartOci(t *testing.T) {
|
||||||
helmlib := &helm.HelmLib{}
|
helmlib := &helm.HelmLib{}
|
||||||
path, err := helmlib.PullChart("oci://ghcr.io/allanger/allangers-charts", "memos", "0.6.0")
|
path, err := helmlib.PullChart(t.Context(), "oci://ghcr.io/allanger/allangers-charts", "memos", "0.6.0")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, "test", path)
|
assert.Equal(t, "test", path)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user