Skip to content

Commit

Permalink
[olm] Include script to generate olm bindata
Browse files Browse the repository at this point in the history
  • Loading branch information
varshaprasad96 committed Sep 28, 2020
1 parent e5b0f37 commit 012b5a6
Show file tree
Hide file tree
Showing 12 changed files with 352 additions and 318 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ GIT_VERSION = $(shell git describe --dirty --tags --always)
GIT_COMMIT = $(shell git rev-parse HEAD)
K8S_VERSION = v1.18.2
GOLANGCI_LINT_VER = "1.30.0"
OLM_VERSION = "0.15.1"
REPO = github.com/operator-framework/operator-sdk
PKGS = $(shell go list ./... | grep -v /vendor/)
TEST_PKGS = $(shell go list ./... | grep -v -E 'github.com/operator-framework/operator-sdk/test/')
Expand Down Expand Up @@ -111,6 +112,9 @@ gen-cli-doc: ## Generate CLI documentation
gen-changelog: ## Generate CHANGELOG.md and migration guide updates
./hack/generate/changelog/gen-changelog.sh

bindata:
./hack/generate/olm_bindata.sh $(OLM_VERSION)

##############################
# Release #
##############################
Expand Down
8 changes: 8 additions & 0 deletions changelog/fragments/store-olm-bindata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
entries:
- description: >
Added feature to the command `operator-sdk olm install` that allows installing OLM version 0.15.1 without
fetching the manifest from Github.
kind: "addition"
breaking: false
11 changes: 0 additions & 11 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,6 @@ github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q
github.com/xlab/handysort v0.0.0-20150421192137-fb3537ed64a1/go.mod h1:QcJo0QPSfTONNIgpN5RA8prR7fF8nkF6cTWTcNerRO8=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yvasiyarov/go-metrics v0.0.0-20140926110328-57bccd1ccd43/go.mod h1:aX5oPXxHm3bOH+xeAttToC8pqch2ScQN/JoXYupl6xs=
github.com/yvasiyarov/go-metrics v0.0.0-20150112132944-c25f46c4b940 h1:p7OofyZ509h8DmPLh8Hn+EIIZm/xYhdZHJ9GnXHdr6U=
github.com/yvasiyarov/go-metrics v0.0.0-20150112132944-c25f46c4b940/go.mod h1:aX5oPXxHm3bOH+xeAttToC8pqch2ScQN/JoXYupl6xs=
Expand Down Expand Up @@ -905,8 +904,6 @@ golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKG
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/mod v0.2.0 h1:KU7oHjnv3XNWfa5COkzUifxZmxp1TyI7ImMXqFxLwvQ=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20170114055629-f2499483f923/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down Expand Up @@ -940,8 +937,6 @@ golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20200625001655-4c5254603344 h1:vGXIOMxbNfDTk/aXCmfdLgkrSV+Z2tcbze+pEc3v5W4=
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20200822124328-c89045814202 h1:VvcQYSHwXgi7W+TpUR6A9g6Up98WAHf3f/ulnJ62IyA=
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20181106182150-f42d05182288/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand All @@ -955,8 +950,6 @@ golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208 h1:qwRHBd0NqMbJxfbotnDhm2ByMI1Shq4Y6oRJo21SGJA=
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20170830134202-bb24a47a89ea/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down Expand Up @@ -1034,14 +1027,10 @@ golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtn
golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.0.0-20200403190813-44a64ad78b9b h1:AFZdJUT7jJYXQEC29hYH/WZkoV7+KhwxQGmdZ19yYoY=
golang.org/x/tools v0.0.0-20200403190813-44a64ad78b9b/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20200916150407-587cf2330ce8 h1:lIJ1QeajWjHg0sYO9manyujReNonmQQ4OpYx+BtgawI=
golang.org/x/tools v0.0.0-20200916150407-587cf2330ce8/go.mod h1:z6u4i615ZeAfBE4XtMziQW1fSVJXACjjbWkB/mvPzlU=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gomodules.xyz/jsonpatch/v2 v2.0.1 h1:xyiBuvkD2g5n7cYzx6u2sxQvsAy4QJsZFCzGVdzOXZ0=
gomodules.xyz/jsonpatch/v2 v2.0.1/go.mod h1:IhYNNY4jnS53ZnfE4PAmpKtDpTCj1JFXc+3mwe7XcUU=
gomodules.xyz/jsonpatch/v3 v3.0.1 h1:Te7hKxV52TKCbNYq3t84tzKav3xhThdvSsSp/W89IyI=
Expand Down
2 changes: 1 addition & 1 deletion hack/check-error-log-msg-format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set -o pipefail
source "hack/lib/test_lib.sh"

echo "Checking format of error and log messages..."
allfiles=$(listFiles)
allfiles=$(listFiles|grep -v ./internal/bindata/...)
log_case_output=$(grep -PRn '(Error\((.*[Ee]rr|nil), |^(?!.*(fmt|errors)).+\.Error(f)?\(|Fatal(f)?\(|Info(f)?\(|Warn(f)?\()"[[:lower:]]' $allfiles | sort -u)
if [ -n "${log_case_output}" ]; then
echo -e "Log messages do not begin with upper case:\n${log_case_output}"
Expand Down
2 changes: 1 addition & 1 deletion hack/check-license.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set -o pipefail
source "hack/lib/test_lib.sh"

echo "Checking for license header..."
allfiles=$(listFiles)
allfiles=$(listFiles|grep -v ./internal/bindata/...)
licRes=""
for file in $allfiles; do
if ! head -n3 "${file}" | grep -Eq "(Copyright|generated|GENERATED|Licensed)" ; then
Expand Down
35 changes: 35 additions & 0 deletions hack/generate/olm_bindata.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash

function get_olm_manifests() {
mkdir olm-manifests
echo "downloading olm manifests for version ${1}"
wget -O olm-manifests/olm.yaml "https://github.com/operator-framework/operator-lifecycle-manager/releases/download/${1}/olm.yaml"
wget -O olm-manifests/crds.yaml "https://github.com/operator-framework/operator-lifecycle-manager/releases/download/${1}/crds.yaml"
}

function remove_olm_manifests {
rm -rf olm-manifests
}

# check for files starting with the name "olm-bindata" inside internal/olm folder
function delete_old_olmbindata {
echo "Deleting previous versions of olm-bindata files if they exist"
find internal/bindata/olm -maxdepth 1 -type f -name manifests-* -exec rm {} \;
}

# TODO:
# 1. Modify this to accept multiple versions and download bindata.
# 2. Discuss on the number of olm versions of will be supported.
FILE=internal/bindata/olm/"manifests-"$1.go
if [ -f "$FILE" ]; then
delete_old_olmbindata
get_olm_manifests $1

go get -u github.com/go-bindata/go-bindata/...
$(go env GOPATH)/bin/go-bindata -o manifests-$1.go -pkg olm olm-manifests/
mv manifests-$1.go internal/bindata/olm

remove_olm_manifests
fi

go mod tidy
1 change: 1 addition & 0 deletions hack/tests/subcommand-olm-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ test_version() {

test_version "latest"
test_version "0.10.1"
test_version "0.15.1" # Check installation of OLM for locally stored version of binaries
270 changes: 270 additions & 0 deletions internal/bindata/olm/manifests-0.15.1.go

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package olmbindata
package olm

func GetAvailableOLMVersions() map[string]struct{} {
return map[string]struct{}{
"0.15.1": struct{}{},
}
var availableVersions = map[string]struct{}{
"0.15.1": struct{}{},
}

// HasVersion returns whether version maps to released OLM manifests as bindata.
func HasVersion(version string) bool {
_, ok := availableVersions[version]
return ok
}
42 changes: 15 additions & 27 deletions internal/olm/installer/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"time"

olmapiv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
olmmanifests "github.com/operator-framework/operator-sdk/internal/olmbindata"
olmmanifests "github.com/operator-framework/operator-sdk/internal/bindata/olm"
log "github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -42,11 +42,13 @@ import (
)

const (
olmOperatorName = "olm-operator"
catalogOperatorName = "catalog-operator"
packageServerName = "packageserver"
olmManifestBindataPath = "internal/olmbindata/olm.yaml"
crdManifestBindataPath = "internal/olmbindata/crds.yaml"
olmOperatorName = "olm-operator"
catalogOperatorName = "catalog-operator"
packageServerName = "packageserver"

// These paths are keys to look up internal OLM bindata.
olmManifestBindataPath = "olm-manifests/olm.yaml"
crdManifestBindataPath = "olm-manifests/crds.yaml"
)

type Client struct {
Expand Down Expand Up @@ -175,15 +177,16 @@ func (c Client) getResources(ctx context.Context, version string) ([]unstructure
var crdResources, olmResources []unstructured.Unstructured
var err error

if isAvailableLocally(version) {
log.Infof("Fetching crd.yaml from locally stored bindata in SDK")
crdResources, err = getPackagedManifests("crd")
// If the manifests for the requested version are saved as bindata in SDK, use
// them instead of fetching them from
if olmmanifests.HasVersion(version) {
log.Infof("Fetching crd.yaml and olm.yaml from locally stored bindata in SDK")
crdResources, err = getPackagedManifests(crdManifestBindataPath)
if err != nil {
return nil, err
}

log.Infof("Fetching olm.yaml from locally stored bindata in SDK")
olmResources, err = getPackagedManifests("olm")
olmResources, err = getPackagedManifests(olmManifestBindataPath)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -222,22 +225,7 @@ func (c Client) getOLM(ctx context.Context, version string) ([]unstructured.Unst
return decodeResources(resp.Body)
}

func isAvailableLocally(version string) bool {
availableManifests := olmmanifests.GetAvailableOLMVersions()
_, ok := availableManifests[version]
return ok
}

func getPackagedManifests(manifestName string) ([]unstructured.Unstructured, error) {
var manifestPath string
if manifestName == "olm" {
manifestPath = olmManifestBindataPath
} else if manifestName == "crd" {
manifestPath = crdManifestBindataPath
} else {
return nil, fmt.Errorf("unexpected manifest name %s", manifestName)
}

func getPackagedManifests(manifestPath string) ([]unstructured.Unstructured, error) {
data, err := olmmanifests.Asset(manifestPath)
if err != nil {
return nil, fmt.Errorf("error retrieving bindata asset %v", err)
Expand Down
272 changes: 0 additions & 272 deletions internal/olmbindata/olm_bindata-0.15.1.go

This file was deleted.

9 changes: 8 additions & 1 deletion test/internal/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@ func NewTestContext(env ...string) (tc TestContext, err error) {

// InstallOLM runs 'operator-sdk olm install' and returns any errors emitted by that command.
func (tc TestContext) InstallOLM() error {
cmd := exec.Command(tc.BinaryName, "olm", "install", "--timeout", "4m")
err := tc.InstallOLMVersion("latest")
return err
}

// InstallOLM runs 'operator-sdk olm install' for specific version
// and returns any errors emitted by that command.
func (tc TestContext) InstallOLMVersion(version string) error {
cmd := exec.Command(tc.BinaryName, "olm", "install", "--version", version, "--timeout", "4m")
_, err := tc.Run(cmd)
return err
}
Expand Down

0 comments on commit 012b5a6

Please sign in to comment.