diff --git a/cmd/haulerctl/app/bootstrap.go b/cmd/haulerctl/app/bootstrap.go index c90e12d..06e2567 100644 --- a/cmd/haulerctl/app/bootstrap.go +++ b/cmd/haulerctl/app/bootstrap.go @@ -19,7 +19,7 @@ type deployOpts struct { // NewBootstrapCommand new a new sub command of haulerctl that bootstraps a cluster func NewBootstrapCommand() *cobra.Command { opts := &deployOpts{ - rootOpts: &ro, + rootOpts: &ro, } cmd := &cobra.Command{ diff --git a/cmd/haulerctl/app/create_test.go b/cmd/haulerctl/app/create_test.go index d23bc91..8c4d1d5 100644 --- a/cmd/haulerctl/app/create_test.go +++ b/cmd/haulerctl/app/create_test.go @@ -25,7 +25,7 @@ func Test_createOpts_Run(t *testing.T) { Version: "v1.21.1+k3s1", }, Paths: []string{ - //"../../../testdata/docker-registry", + "../../../testdata/docker-registry", "../../../testdata/rawmanifests", }, Images: []string{}, diff --git a/pkg/apis/hauler.cattle.io/v1alpha1/driver.go b/pkg/apis/hauler.cattle.io/v1alpha1/driver.go index dff6eff..5058d14 100644 --- a/pkg/apis/hauler.cattle.io/v1alpha1/driver.go +++ b/pkg/apis/hauler.cattle.io/v1alpha1/driver.go @@ -74,7 +74,7 @@ func (r rke2) Images() ([]string, error) { return []string{}, n func (r rke2) BinURL() string { return "" } func (r rke2) LibPath() string { return "" } func (r rke2) EtcPath() string { return "" } -func (r rke2) Config() (*map[string]interface{}, error) { return nil, nil } +func (r rke2) Config() (*map[string]interface{}, error) { return nil, nil } func (r rke2) SystemObjects() (objs []object.ObjMetadata) { return objs } //NewDriver will return the appropriate driver given a kind, defaults to k3s diff --git a/pkg/bootstrap/booter.go b/pkg/bootstrap/booter.go index d3d5354..1989a65 100644 --- a/pkg/bootstrap/booter.go +++ b/pkg/bootstrap/booter.go @@ -25,7 +25,7 @@ type Booter interface { type booter struct { Package v1alpha1.Package - fs fs.PkgFs + fs fs.PkgFs } //NewBooter will build a new booter given a path to a directory containing a hauler package.json @@ -39,7 +39,7 @@ func NewBooter(pkgPath string) (*booter, error) { return &booter{ Package: pkg, - fs: fsys, + fs: fsys, }, nil } @@ -47,10 +47,18 @@ func (b booter) Init() error { d := v1alpha1.NewDriver(b.Package.Spec.Driver.Kind) //TODO: Feel like there's a better way to do this - if err := b.moveBin(); err != nil { return err } - if err := b.moveImages(d); err != nil { return err } - if err := b.moveBundles(d); err != nil { return err } - if err := b.moveCharts(d); err != nil { return err } + if err := b.moveBin(); err != nil { + return err + } + if err := b.moveImages(d); err != nil { + return err + } + if err := b.moveBundles(d); err != nil { + return err + } + if err := b.moveCharts(d); err != nil { + return err + } return nil } @@ -67,7 +75,7 @@ func (b booter) Boot(ctx context.Context, d v1alpha1.Drive) error { //TODO: Generic cmd := exec.Command("/bin/sh", "/opt/hauler/bin/k3s-init.sh") - cmd.Env = append(os.Environ(), []string{ + cmd.Env = append(os.Environ(), []string{ "INSTALL_K3S_SKIP_DOWNLOAD=true", "INSTALL_K3S_SELINUX_WARN=true", "INSTALL_K3S_SKIP_SELINUX_RPM=true", diff --git a/pkg/bootstrap/kube.go b/pkg/bootstrap/kube.go index dd64326..9c07c20 100644 --- a/pkg/bootstrap/kube.go +++ b/pkg/bootstrap/kube.go @@ -31,7 +31,7 @@ func waitForDriver(ctx context.Context, d v1alpha1.Drive) error { return errors.New("timed out waiting for driver to provision") } - time.Sleep(1*time.Second) + time.Sleep(1 * time.Second) } cfg, err := kube.NewKubeConfig() @@ -56,7 +56,7 @@ func installChart(cf *genericclioptions.ConfigFlags, chart *chart.Chart, release client := action.NewInstall(actionConfig) client.ReleaseName = releaseName - client.Namespace, cf.Namespace = namespace, stringptr(namespace) // TODO: Not sure why this needs to be set twice + client.Namespace, cf.Namespace = namespace, stringptr(namespace) // TODO: Not sure why this needs to be set twice client.CreateNamespace = true client.Wait = true diff --git a/pkg/log/log.go b/pkg/log/log.go index 15e50c2..9eef734 100644 --- a/pkg/log/log.go +++ b/pkg/log/log.go @@ -19,7 +19,7 @@ type standardLogger struct { } type Event struct { - id int + id int message string } diff --git a/pkg/packager/images.go b/pkg/packager/images.go index 8a58f37..fa9be46 100644 --- a/pkg/packager/images.go +++ b/pkg/packager/images.go @@ -20,6 +20,7 @@ type Imager interface { } type discoveredImages []string + func (d discoveredImages) Images() ([]string, error) { return d, nil } @@ -79,7 +80,9 @@ func ResolveRemoteRefs(images ...string) (map[name.Reference]v1.Image, error) { m := make(map[name.Reference]v1.Image) for _, i := range images { - if i == "" { continue } + if i == "" { + continue + } //TODO: This will error out if remote is a v1 image, do better error handling for this ref, err := name.ParseReference(i) @@ -98,8 +101,15 @@ func ResolveRemoteRefs(images ...string) (map[name.Reference]v1.Image, error) { return m, nil } +//TODO: Add user defined paths var knownImagePaths = []string{ + // Deployments & DaemonSets + "{.spec.template.spec.initContainers[*].image}", "{.spec.template.spec.containers[*].image}", + + // Pods + "{.spec.initContainers[*].image}", + "{.spec.containers[*].image}", } ////imageFromRuntimeObject will return any images found in known obj specs @@ -135,6 +145,6 @@ func parseJSONPath(input interface{}, parser *jsonpath.JSONPath, template string return nil, err } - r:= strings.Split(buf.String(), " ") + r := strings.Split(buf.String(), " ") return r, nil -} \ No newline at end of file +} diff --git a/testdata/rawmanifests/deployment.yaml b/testdata/rawmanifests/deployment.yaml deleted file mode 100644 index 13ba734..0000000 --- a/testdata/rawmanifests/deployment.yaml +++ /dev/null @@ -1,25 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: podinfo -spec: - selector: - matchLabels: - app: podinfo - tier: frontend - replicas: 1 - template: - metadata: - labels: - app: podinfo - tier: frontend - spec: - containers: - - name: podinfo - image: stefanprodan/podinfo:5.2.1 - resources: - requests: - cpu: 100m - memory: 100Mi - ports: - - containerPort: 80 diff --git a/testdata/rawmanifests/podinfo.yaml b/testdata/rawmanifests/podinfo.yaml new file mode 100644 index 0000000..f8378cd --- /dev/null +++ b/testdata/rawmanifests/podinfo.yaml @@ -0,0 +1,109 @@ +--- +# Source: podinfo/templates/service.yaml +apiVersion: v1 +kind: Service +metadata: + name: tester-podinfo + labels: + helm.sh/chart: podinfo-5.2.1 + app.kubernetes.io/name: tester-podinfo + app.kubernetes.io/version: "5.2.1" + app.kubernetes.io/managed-by: Helm +spec: + type: ClusterIP + ports: + - port: 9898 + targetPort: http + protocol: TCP + name: http + - port: 9999 + targetPort: grpc + protocol: TCP + name: grpc + selector: + app.kubernetes.io/name: tester-podinfo +--- +# Source: podinfo/templates/deployment.yaml +apiVersion: apps/v1 +kind: Deployment +metadata: + name: tester-podinfo + labels: + helm.sh/chart: podinfo-5.2.1 + app.kubernetes.io/name: tester-podinfo + app.kubernetes.io/version: "5.2.1" + app.kubernetes.io/managed-by: Helm +spec: + replicas: 1 + strategy: + type: RollingUpdate + rollingUpdate: + maxUnavailable: 1 + selector: + matchLabels: + app.kubernetes.io/name: tester-podinfo + template: + metadata: + labels: + app.kubernetes.io/name: tester-podinfo + annotations: + prometheus.io/scrape: "true" + prometheus.io/port: "9898" + spec: + terminationGracePeriodSeconds: 30 + containers: + - name: podinfo + image: "ghcr.io/stefanprodan/podinfo:5.2.1" + imagePullPolicy: IfNotPresent + command: + - ./podinfo + - --port=9898 + - --cert-path=/data/cert + - --port-metrics=9797 + - --grpc-port=9999 + - --grpc-service-name=podinfo + - --level=info + - --random-delay=false + - --random-error=false + env: + - name: PODINFO_UI_COLOR + value: "#34577c" + ports: + - name: http + containerPort: 9898 + protocol: TCP + - name: http-metrics + containerPort: 9797 + protocol: TCP + - name: grpc + containerPort: 9999 + protocol: TCP + livenessProbe: + exec: + command: + - podcli + - check + - http + - localhost:9898/healthz + initialDelaySeconds: 1 + timeoutSeconds: 5 + readinessProbe: + exec: + command: + - podcli + - check + - http + - localhost:9898/readyz + initialDelaySeconds: 1 + timeoutSeconds: 5 + volumeMounts: + - name: data + mountPath: /data + resources: + limits: null + requests: + cpu: 1m + memory: 16Mi + volumes: + - name: data + emptyDir: {} diff --git a/testdata/rawmanifests/service.yaml b/testdata/rawmanifests/service.yaml deleted file mode 100644 index d97a5b5..0000000 --- a/testdata/rawmanifests/service.yaml +++ /dev/null @@ -1,14 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: frontend - labels: - app: guestbook - tier: frontend -spec: - type: NodePort - ports: - - port: 80 - selector: - app: guestbook - tier: frontend