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
 | 
			
		||||
bin/*
 | 
			
		||||
Dockerfile.cross
 | 
			
		||||
 | 
			
		||||
image.tar
 | 
			
		||||
# Test binary, built with `go test -c`
 | 
			
		||||
*.test
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -67,11 +67,11 @@ spec:
 | 
			
		||||
        imagePullPolicy: Never
 | 
			
		||||
        name: manager
 | 
			
		||||
        ports: []
 | 
			
		||||
        securityContext:
 | 
			
		||||
          allowPrivilegeEscalation: false
 | 
			
		||||
          capabilities:
 | 
			
		||||
            drop:
 | 
			
		||||
            - "ALL"
 | 
			
		||||
        #securityContext:
 | 
			
		||||
        #  allowPrivilegeEscalation: false
 | 
			
		||||
        #  capabilities:
 | 
			
		||||
        #    drop:
 | 
			
		||||
        #    - "ALL"
 | 
			
		||||
        livenessProbe:
 | 
			
		||||
          httpGet:
 | 
			
		||||
            path: /healthz
 | 
			
		||||
 
 | 
			
		||||
@@ -28,6 +28,7 @@ import (
 | 
			
		||||
 | 
			
		||||
	yahov1alpha1 "github.com/allanger/yaho/api/v1alpha1"
 | 
			
		||||
	"github.com/allanger/yaho/internal/downloader"
 | 
			
		||||
	"github.com/allanger/yaho/internal/tools/helm"
 | 
			
		||||
	k8serrors "k8s.io/apimachinery/pkg/api/errors"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
@@ -78,9 +79,10 @@ func (r *HelmReleaseReconciler) Reconcile(ctx context.Context, req ctrl.Request)
 | 
			
		||||
		return reconcileResult, nil
 | 
			
		||||
	}
 | 
			
		||||
	log.Info("Pulled a chart", "path", path)
 | 
			
		||||
	//path, err := downloader.PullChart(repository, chart, version)
 | 
			
		||||
	//if err != nil { return ... }
 | 
			
		||||
	//err := helm.InstallOrUpdate(); if err != nil { return ...}
 | 
			
		||||
	helmlib := &helm.HelmLib{}
 | 
			
		||||
	if err := helmlib.InstallChart(ctx, path, helmReleaseCR.Name, helmReleaseCR.Namespace); err != nil {
 | 
			
		||||
		return reconcileResult, nil
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	return ctrl.Result{}, nil
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -6,12 +6,10 @@ import (
 | 
			
		||||
	"os"
 | 
			
		||||
	"strings"
 | 
			
		||||
 | 
			
		||||
	"helm.sh/helm/pkg/chartutil"
 | 
			
		||||
	"helm.sh/helm/pkg/engine"
 | 
			
		||||
	"helm.sh/helm/v3/pkg/action"
 | 
			
		||||
	"helm.sh/helm/v3/pkg/chart/loader"
 | 
			
		||||
	"helm.sh/helm/v3/pkg/cli"
 | 
			
		||||
	"helm.sh/helm/v3/pkg/registry"
 | 
			
		||||
	"honnef.co/go/tools/go/loader"
 | 
			
		||||
	"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)
 | 
			
		||||
	}
 | 
			
		||||
	client.Settings = cl
 | 
			
		||||
	client.UntarDir = workdir
 | 
			
		||||
	client.Version = version
 | 
			
		||||
	client.DestDir = workdir
 | 
			
		||||
	path, err := client.Run(chartRemote)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.Error(err, "An unexpected error occurred while fetching the chart", "chart", chartRemote)
 | 
			
		||||
		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 {
 | 
			
		||||
@@ -67,25 +68,13 @@ func (h *HelmLib) InstallChart(ctx context.Context, path string, name, namespace
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	values := chartutil.Values{}
 | 
			
		||||
	values["Values"] = nil 
 | 
			
		||||
	values["Release"] = map[string]string{
 | 
			
		||||
		"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)
 | 
			
		||||
	client := action.NewInstall(&action.Configuration{})
 | 
			
		||||
	client.DryRun = true
 | 
			
		||||
	release, err := client.RunWithContext(ctx, chartObj, nil)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	for file, data := range files {
 | 
			
		||||
		log.Info("File is rendered", "data", file)
 | 
			
		||||
	}
 | 
			
		||||
	log.Info("Got a manifest", "manifest", release.Manifest)
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -9,14 +9,14 @@ import (
 | 
			
		||||
 | 
			
		||||
func TestPullChart(t *testing.T) {
 | 
			
		||||
	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.Equal(t, "test", path)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func TestPullChartOci(t *testing.T) {
 | 
			
		||||
	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.Equal(t, "test", path)
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user