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 29, 2020
1 parent e5b0f37 commit 7416af5
Show file tree
Hide file tree
Showing 13 changed files with 372 additions and 329 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
2 changes: 1 addition & 1 deletion hack/tests/subcommand-olm-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,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
}
44 changes: 16 additions & 28 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("Using locally stored resource manifests")
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,25 +225,10 @@ 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)
return nil, fmt.Errorf("error retrieving bindata asset: %v", err)
}

reader := bytes.NewReader(data)
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
28 changes: 19 additions & 9 deletions website/content/en/docs/contribution-guidelines/releasing.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,23 @@ For major and minor releases, `master` should be locked between steps 3 and 6 so
or have a pre-release version, ex. `v1.2.0+git`. Otherwise commits might be built into a release that shouldn't be.
For patch releases, ensure all required bugs are [cherry-picked](#cherry-picking), then the release branch `v1.3.x` should be locked down.

### 1. Netlify configuration
### 1. Update OLM bindata

This step is to be preferably performed only during major releases. Update the `OLM_VERSION` variable in Makefile to the latest successful release of OLM. Run `make bindata` so that `internal/bindata/olm` is updated. Also, update the `availableVersions` map in `internal/bindata/olm/versions.go` to contain the version of OLM which you have specified in the Makefile.

Submit a PR with the changes and merge it with master.

**Important:**
- Update OLM bindata just before starting the release so that we have the latest OLM version.
- Verify that the release of OLM version which you specify in Makefile is successful.

### 2. Netlify configuration

**Important:** ensure a release branch-to-subdomain mapping exists in the SDK's Netlify configuration _prior to creating a release_,
ex. `v1.3.x` to `https://v1-3-x.sdk.operatorframework.io`. You can ping SDK [approvers][doc-owners] to ensure a
[release branch](#release-branches) is created prior to the release and that this mapping is created.

### 2. Create release branch for Netlify
### 3. Create release branch for Netlify

The release branch must be created before the release occurs to appease the Netlify website configuration demons.
You can do so by running the following before proceeding with the release, assuming the upstream SDK is the `upstream` remote repo:
Expand All @@ -220,7 +230,7 @@ $ git checkout -b v1.3.x
$ git push -u upstream v1.3.x
```

### 3. Create a PR for release version, CHANGELOG.md, and migration guide updates
### 4. Create a PR for release version, CHANGELOG.md, and migration guide updates

Once all PR's needed for a release have been merged, branch from `master`:

Expand Down Expand Up @@ -262,11 +272,11 @@ and add the following lines under `[[params.versions]]` for `master`:
url = "https://v1-3-x.sdk.operatorframework.io"
```

### 4. Lock down proper branch
### 5. Lock down proper branch
Create and merge a new PR for `release-v1.3.0`. Once this PR is merged, lock down the master or release branch
to prevent further commits between this and step 7. See [this section](#locking-down-branches) for steps to do so.

### 5. Create a release tag, binaries, and signatures
### 6. Create a release tag, binaries, and signatures

The top-level `release.sh` script will take care of verifying versions in files described in step 3, and tagging and verifying the tag, as well as building binaries and generating signatures by calling `make release`.

Expand Down Expand Up @@ -304,7 +314,7 @@ Once this tag passes CI, go to step 6. For more info on tagging, see the [releas

**Note:** If CI fails for some reason, you will have to revert the tagged commit, re-commit, and make a new PR.

### 6. Fast-forward the `latest` and release branches
### 7. Fast-forward the `latest` and release branches

The `latest` branch points to the latest release tag to keep the main website subdomain up-to-date.
Run the following commands to do so:
Expand All @@ -323,7 +333,7 @@ $ git reset --hard tags/v1.3.0
$ git push -f upstream v1.3.x
```

### 7. Create a PR for post-release version updates
### 8. Create a PR for post-release version updates

Check out a new branch from `master` or release branch and commit the following changes:

Expand All @@ -333,7 +343,7 @@ Check out a new branch from `master` or release branch and commit the following

Create a new PR for this branch targeting the `master` or release branch.

### 8. Releasing binaries, signatures, and release notes
### 9. Releasing binaries, signatures, and release notes

The final step is to upload binaries, their signature files, and release notes from `CHANGELOG.md` for `v1.3.0`.
To create a GitHub release:
Expand All @@ -346,7 +356,7 @@ To create a GitHub release:

**Note:** if this is a pre-release, make sure to check the `This is a pre-release` box under the file attachment frame. If you are not sure what this means, ask another maintainer.

### 9. Unlock proper branch
### 10. Unlock proper branch
Unlock the `master` or release branch after the Github release is complete.
See [this section](#locking-down-branches) for steps to do so.

Expand Down

0 comments on commit 7416af5

Please sign in to comment.