Skip to content

Commit

Permalink
Replace packr with golang's native embed package (#30)
Browse files Browse the repository at this point in the history
* packr replace

* packr replace
  • Loading branch information
kon-angelo authored Apr 26, 2021
1 parent 94ea26e commit cb4cbfc
Show file tree
Hide file tree
Showing 348 changed files with 6,613 additions and 17,142 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,3 @@ TODO
# Virtual go & fuse
.virtualgo
.fuse_hidden*

# Packr generated files
*-packr.go
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
############# builder
FROM golang:1.15.8 AS builder
FROM golang:1.16.2 AS builder

WORKDIR /go/src/github.com/gardener/gardener-extension-os-gardenlinux
COPY . .
RUN make install-requirements && make generate && make install

############# gardener-extension-os-gardenlinux
FROM alpine:3.13.2 AS gardener-extension-os-gardenlinux
FROM alpine:3.13.5 AS gardener-extension-os-gardenlinux

COPY --from=builder /go/bin/gardener-extension-os-gardenlinux /gardener-extension-os-gardenlinux
ENTRYPOINT ["/gardener-extension-os-gardenlinux"]
5 changes: 0 additions & 5 deletions LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,6 @@ gopkg.in/yaml.v2.
Copyright 2011-2016 Canonical Ltd.
Apache 2 license (https://github.com/go-yaml/yaml/blob/v2/LICENSE)

Packr.
https://github.com/gobuffalo/packr
Copyright (c) 2016 Mark Bates.
MIT license (https://github.com/gobuffalo/packr/blob/master/LICENSE.txt)

Cobra.
https://github.com/spf13/cobra
Copyright 2019 Steve Francia.
Expand Down
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ docker-images:

.PHONY: install-requirements
install-requirements:
@go install -mod=vendor $(REPO_ROOT)/vendor/github.com/gobuffalo/packr/v2/packr2
@go install -mod=vendor $(REPO_ROOT)/vendor/github.com/onsi/ginkgo/ginkgo
@$(REPO_ROOT)/vendor/github.com/gardener/gardener/hack/install-requirements.sh
@$(REPO_ROOT)/hack/update-github-templates.sh
Expand Down
8 changes: 3 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
module github.com/gardener/gardener-extension-os-gardenlinux

go 1.15
go 1.16

require (
github.com/ahmetb/gen-crd-api-reference-docs v0.2.0
github.com/gardener/gardener v1.19.1
github.com/gobuffalo/packr v1.30.1
github.com/gobuffalo/packr/v2 v2.5.1
github.com/onsi/ginkgo v1.14.1
github.com/gardener/gardener v1.21.0
github.com/onsi/ginkgo v1.14.2
github.com/onsi/gomega v1.10.5
github.com/spf13/cobra v1.1.1
k8s.io/api v0.20.2
Expand Down
185 changes: 31 additions & 154 deletions go.sum

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion hack/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
_ "github.com/gardener/gardener/hack/api-reference/template"

_ "github.com/ahmetb/gen-crd-api-reference-docs"
_ "github.com/gobuffalo/packr/v2/packr2"
_ "github.com/onsi/ginkgo/ginkgo"
_ "k8s.io/code-generator"
)
11 changes: 6 additions & 5 deletions pkg/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
package generator

import (
"embed"

ostemplate "github.com/gardener/gardener/extensions/pkg/controller/operatingsystemconfig/oscommon/template"
extensionsv1alpha1 "github.com/gardener/gardener/pkg/apis/extensions/v1alpha1"
"github.com/gobuffalo/packr/v2"
"k8s.io/apimachinery/pkg/util/runtime"
)

Expand All @@ -28,14 +29,14 @@ func additionalValues(*extensionsv1alpha1.OperatingSystemConfig) (map[string]int
return nil, nil
}

//go:generate packr2
//go:embed templates/*
var templates embed.FS

func init() {
box := packr.New("templates", "./templates")
cloudInitTemplateString, err := box.FindString("cloud-init.gardenlinux.template")
cloudInitTemplateString, err := templates.ReadFile("templates/cloud-init.gardenlinux.template")
runtime.Must(err)

cloudInitTemplate, err := ostemplate.NewTemplate("cloud-init").Parse(cloudInitTemplateString)
cloudInitTemplate, err := ostemplate.NewTemplate("cloud-init").Parse(string(cloudInitTemplateString))
runtime.Must(err)
cloudInitGenerator = ostemplate.NewCloudInitGenerator(cloudInitTemplate, ostemplate.DefaultUnitsPath, cmd, additionalValues)
}
Expand Down
13 changes: 6 additions & 7 deletions pkg/generator/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ package generator_test

import (
gardenlinux_generator "github.com/gardener/gardener-extension-os-gardenlinux/pkg/generator"
"github.com/gardener/gardener-extension-os-gardenlinux/pkg/generator/testfiles"

commongen "github.com/gardener/gardener/extensions/pkg/controller/operatingsystemconfig/oscommon/generator"
"github.com/gardener/gardener/extensions/pkg/controller/operatingsystemconfig/oscommon/generator/test"
"github.com/gardener/gardener/pkg/apis/extensions/v1alpha1"
"github.com/gobuffalo/packr"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
Expand Down Expand Up @@ -88,12 +88,11 @@ dataKey: token`)
var _ = Describe("Garden Linux OS Generator Test", func() {

Describe("Conformance Tests", func() {
var box = packr.NewBox("./testfiles")
g := gardenlinux_generator.CloudInitGenerator()
test.DescribeTest(gardenlinux_generator.CloudInitGenerator(), box)()
test.DescribeTest(gardenlinux_generator.CloudInitGenerator(), testfiles.Files)()

It("[docker] [bootstrap] should render correctly ", func() {
expectedCloudInit, err := box.Find("docker-bootstrap")
expectedCloudInit, err := testfiles.Files.ReadFile("docker-bootstrap")
Expect(err).NotTo(HaveOccurred())

osc.Bootstrap = true
Expand All @@ -106,7 +105,7 @@ var _ = Describe("Garden Linux OS Generator Test", func() {
})

It("[docker] [reconcile] should render correctly", func() {
expectedCloudInit, err := box.Find("docker-reconcile")
expectedCloudInit, err := testfiles.Files.ReadFile("docker-reconcile")
Expect(err).NotTo(HaveOccurred())

osc.Bootstrap = false
Expand All @@ -119,7 +118,7 @@ var _ = Describe("Garden Linux OS Generator Test", func() {
})

It("[containerd] [bootstrap] should render correctly", func() {
expectedCloudInit, err := box.Find("containerd-bootstrap")
expectedCloudInit, err := testfiles.Files.ReadFile("containerd-bootstrap")
Expect(err).NotTo(HaveOccurred())

osc.Bootstrap = true
Expand All @@ -132,7 +131,7 @@ var _ = Describe("Garden Linux OS Generator Test", func() {
})

It("[containerd] [reconcile] should render correctly bootstrap", func() {
expectedCloudInit, err := box.Find("containerd-reconcile")
expectedCloudInit, err := testfiles.Files.ReadFile("containerd-reconcile")
Expect(err).NotTo(HaveOccurred())

osc.Bootstrap = false
Expand Down
21 changes: 21 additions & 0 deletions pkg/generator/testfiles/embed.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) 2021 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package testfiles

import "embed"

// Files contains the contents of the testfiles directory
//go:embed cloud-* containerd-* docker-*
var Files embed.FS

This file was deleted.

Loading

0 comments on commit cb4cbfc

Please sign in to comment.