Skip to content

Commit

Permalink
pkg/k8s: use go embed for the CRD files
Browse files Browse the repository at this point in the history
In Golang 1.16 we can use go embed to embed files without using a 3rd
party library. Thus we can remove the go-bindata from our list of
dependencies.

Signed-off-by: André Martins <andre@cilium.io>
  • Loading branch information
aanm committed Apr 23, 2021
1 parent 51bdb84 commit 9b70ef1
Show file tree
Hide file tree
Showing 52 changed files with 49 additions and 3,977 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
go.sum linguist-generated
examples/kubernetes/connectivity-check/connectivity-*.yaml linguist-generated
examples/crds/*.yaml linguist-generated
pkg/k8s/apis/cilium.io/v2/client/crds/*.yaml linguist-generated
Documentation/cmdref/** linguist-generated
2 changes: 1 addition & 1 deletion CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ Makefile* @cilium/build
/Documentation/yaml.config @cilium/docs-structure
/envoy/ @cilium/proxy
/examples/ @cilium/docs-structure
/examples/crds/ @cilium/kubernetes
/pkg/k8s/apis/cilium.io/v2/client/crds/ @cilium/kubernetes
/examples/kubernetes/ @cilium/kubernetes
/examples/minikube/ @cilium/kubernetes
*.Jenkinsfile @cilium/ci-structure
Expand Down
18 changes: 9 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ TESTPKGS_EVAL := $(subst github.com/cilium/cilium/,,$(shell echo $(GOFILES) | \
TESTPKGS_EVAL += "test/helpers/logutils"
TESTPKGS ?= $(TESTPKGS_EVAL)
GOLANG_SRCFILES := $(shell for pkg in $(subst github.com/cilium/cilium/,,$(GOFILES)); do find $$pkg -name *.go -print; done | grep -v vendor | sort | uniq)
K8S_CRD_EVAL := $(addprefix $(ROOT_DIR)/,$(shell git ls-files $(ROOT_DIR)/examples/crds | grep -v .gitignore | tr "\n" ' '))
K8S_CRD_EVAL := $(addprefix $(ROOT_DIR)/,$(shell git ls-files $(ROOT_DIR)/pkg/k8s/apis/cilium.io/v2/client/crds $(ROOT_DIR)/pkg/k8s/apis/cilium.io/v2alpha1/client/crds | grep -v .gitignore | tr "\n" ' '))
K8S_CRD_FILES ?= $(K8S_CRD_EVAL)

SWAGGER_VERSION := v0.25.0
Expand Down Expand Up @@ -306,14 +306,14 @@ manifests: ## Generate K8s manifests e.g. CRD, RBAC etc.
$(eval TMPDIR := $(shell mktemp -d))
cd "./vendor/sigs.k8s.io/controller-tools/cmd/controller-gen" && \
go run ./... $(CRD_OPTIONS) paths="$(PWD)/pkg/k8s/apis/cilium.io/v2;$(PWD)/pkg/k8s/apis/cilium.io/v2alpha1" output:crd:artifacts:config="$(TMPDIR)";
mv ${TMPDIR}/cilium.io_ciliumnetworkpolicies.yaml ./examples/crds/ciliumnetworkpolicies.yaml
mv ${TMPDIR}/cilium.io_ciliumclusterwidenetworkpolicies.yaml ./examples/crds/ciliumclusterwidenetworkpolicies.yaml
mv ${TMPDIR}/cilium.io_ciliumendpoints.yaml ./examples/crds/ciliumendpoints.yaml
mv ${TMPDIR}/cilium.io_ciliumidentities.yaml ./examples/crds/ciliumidentities.yaml
mv ${TMPDIR}/cilium.io_ciliumnodes.yaml ./examples/crds/ciliumnodes.yaml
mv ${TMPDIR}/cilium.io_ciliumexternalworkloads.yaml ./examples/crds/ciliumexternalworkloads.yaml
mv ${TMPDIR}/cilium.io_ciliumlocalredirectpolicies.yaml ./examples/crds/ciliumlocalredirectpolicies.yaml
mv ${TMPDIR}/cilium.io_ciliumegressnatpolicies.yaml ./examples/crds/ciliumegressnatpolicies.yaml
mv ${TMPDIR}/cilium.io_ciliumnetworkpolicies.yaml ./pkg/k8s/apis/cilium.io/v2/client/crds/ciliumnetworkpolicies.yaml
mv ${TMPDIR}/cilium.io_ciliumclusterwidenetworkpolicies.yaml ./pkg/k8s/apis/cilium.io/v2/client/crds/ciliumclusterwidenetworkpolicies.yaml
mv ${TMPDIR}/cilium.io_ciliumendpoints.yaml ./pkg/k8s/apis/cilium.io/v2/client/crds/ciliumendpoints.yaml
mv ${TMPDIR}/cilium.io_ciliumidentities.yaml ./pkg/k8s/apis/cilium.io/v2/client/crds/ciliumidentities.yaml
mv ${TMPDIR}/cilium.io_ciliumnodes.yaml ./pkg/k8s/apis/cilium.io/v2/client/crds/ciliumnodes.yaml
mv ${TMPDIR}/cilium.io_ciliumexternalworkloads.yaml ./pkg/k8s/apis/cilium.io/v2/client/crds/ciliumexternalworkloads.yaml
mv ${TMPDIR}/cilium.io_ciliumlocalredirectpolicies.yaml ./pkg/k8s/apis/cilium.io/v2/client/crds/ciliumlocalredirectpolicies.yaml
mv ${TMPDIR}/cilium.io_ciliumegressnatpolicies.yaml ./pkg/k8s/apis/cilium.io/v2/client/crds/ciliumegressnatpolicies.yaml
rm -rf $(TMPDIR)

generate-api: api/v1/openapi.yaml ## Generate cilium-agent client, model and server code from openapi spec.
Expand Down
1 change: 1 addition & 0 deletions examples/crds
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ require (
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/libnetwork v0.0.0-20190128195551-d8d4c8cf03d7
github.com/fsnotify/fsnotify v1.4.10-0.20200417215612-7f4cf4dd2b52
github.com/go-bindata/go-bindata/v3 v3.1.3
github.com/go-openapi/errors v0.19.9
github.com/go-openapi/loads v0.20.0
github.com/go-openapi/runtime v0.19.26
Expand Down
3 changes: 0 additions & 3 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

410 changes: 0 additions & 410 deletions pkg/k8s/apis/cilium.io/v2/client/bindata.go

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
49 changes: 36 additions & 13 deletions pkg/k8s/apis/cilium.io/v2/client/register.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017-2020 Authors of Cilium
// Copyright 2017-2021 Authors of Cilium
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -16,6 +16,7 @@ package client

import (
"context"
_ "embed"
goerrors "errors"
"fmt"
"time"
Expand Down Expand Up @@ -114,6 +115,32 @@ func CreateCustomResourceDefinitions(clientset apiextensionsclient.Interface) er
return g.Wait()
}

var (
//go:embed crds/ciliumnetworkpolicies.yaml
crdsCiliumnetworkpolicies []byte

//go:embed crds/ciliumclusterwidenetworkpolicies.yaml
crdsCiliumclusterwidenetworkpolicies []byte

//go:embed crds/ciliumendpoints.yaml
crdsCiliumendpoints []byte

//go:embed crds/ciliumidentities.yaml
crdsCiliumidentities []byte

//go:embed crds/ciliumnodes.yaml
crdsCiliumnodes []byte

//go:embed crds/ciliumexternalworkloads.yaml
crdsCiliumexternalworkloads []byte

//go:embed crds/ciliumlocalredirectpolicies.yaml
crdsCiliumlocalredirectpolicies []byte

//go:embed crds/ciliumegressnatpolicies.yaml
crdsCiliumegressnatpolicies []byte
)

// GetPregeneratedCRD returns the pregenerated CRD based on the requested CRD
// name. The pregenerated CRDs are generated by the controller-gen tool and
// serialized into binary form by go-bindata. This function retrieves CRDs from
Expand All @@ -128,29 +155,25 @@ func GetPregeneratedCRD(crdName string) apiextensionsv1.CustomResourceDefinition

switch crdName {
case CNPCRDName:
crdBytes, err = examplesCrdsCiliumnetworkpoliciesYamlBytes()
crdBytes = crdsCiliumnetworkpolicies
case CCNPCRDName:
crdBytes, err = examplesCrdsCiliumclusterwidenetworkpoliciesYamlBytes()
crdBytes = crdsCiliumclusterwidenetworkpolicies
case CEPCRDName:
crdBytes, err = examplesCrdsCiliumendpointsYamlBytes()
crdBytes = crdsCiliumendpoints
case CIDCRDName:
crdBytes, err = examplesCrdsCiliumidentitiesYamlBytes()
crdBytes = crdsCiliumidentities
case CNCRDName:
crdBytes, err = examplesCrdsCiliumnodesYamlBytes()
crdBytes = crdsCiliumnodes
case CEWCRDName:
crdBytes, err = examplesCrdsCiliumexternalworkloadsYamlBytes()
crdBytes = crdsCiliumexternalworkloads
case CLRPCRDName:
crdBytes, err = examplesCrdsCiliumlocalredirectpoliciesYamlBytes()
crdBytes = crdsCiliumlocalredirectpolicies
case CENPCRDName:
crdBytes, err = examplesCrdsCiliumegressnatpoliciesYamlBytes()
crdBytes = crdsCiliumegressnatpolicies
default:
scopedLog.Fatal("Pregenerated CRD does not exist")
}

if err != nil {
scopedLog.WithError(err).Fatal("Error retrieving pregenerated CRD")
}

ciliumCRD := apiextensionsv1.CustomResourceDefinition{}
err = yaml.Unmarshal(crdBytes, &ciliumCRD)
if err != nil {
Expand Down
4 changes: 1 addition & 3 deletions tools/tools.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2019-2020 Authors of Cilium
// Copyright 2019-2021 Authors of Cilium
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -19,8 +19,6 @@ package tools
import (
_ "github.com/cilium/customvet"
_ "github.com/cilium/deepequal-gen"
_ "github.com/go-bindata/go-bindata/v3"
_ "github.com/go-bindata/go-bindata/v3/go-bindata"
_ "k8s.io/code-generator"
_ "k8s.io/code-generator/cmd/client-gen"
_ "sigs.k8s.io/controller-tools/cmd/controller-gen"
Expand Down
13 changes: 0 additions & 13 deletions vendor/github.com/go-bindata/go-bindata/v3/.drone.yml

This file was deleted.

16 changes: 0 additions & 16 deletions vendor/github.com/go-bindata/go-bindata/v3/.gitignore

This file was deleted.

79 changes: 0 additions & 79 deletions vendor/github.com/go-bindata/go-bindata/v3/CONTRIBUTING.md

This file was deleted.

3 changes: 0 additions & 3 deletions vendor/github.com/go-bindata/go-bindata/v3/LICENSE

This file was deleted.

2 changes: 0 additions & 2 deletions vendor/github.com/go-bindata/go-bindata/v3/Makefile

This file was deleted.

Loading

0 comments on commit 9b70ef1

Please sign in to comment.