Skip to content

Commit

Permalink
use basic.BasicTemplate, change yaml to alphabetic order
Browse files Browse the repository at this point in the history
  • Loading branch information
oksana-grishchenko committed Jul 12, 2024
1 parent 202e463 commit f8142bf
Show file tree
Hide file tree
Showing 7 changed files with 905 additions and 217 deletions.
28 changes: 14 additions & 14 deletions tools/everest-operator_test.yaml
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
schema: olm.template.basic
entries:
- schema: olm.package
defaultChannel: stable-v0
- defaultChannel: stable-v0
name: everest-operator
- schema: olm.channel
name: fast-v0
entries:
schema: olm.package
- entries:
- name: everest-operator.v0.0.0
- name: everest-operator.v0.9.0
- name: everest-operator.v0.9.1
replaces: everest-operator.v0.0.0
skips:
- everest-operator.v0.0.0
- everest-operator.v0.9.0
name: fast-v0
package: everest-operator
- schema: olm.channel
name: fast-v1
entries:
schema: olm.channel
- entries:
- name: everest-operator.v0.0.0
- name: everest-operator.v0.9.0
- name: everest-operator.v0.9.1-rc1
replaces: everest-operator.v0.0.0
skips:
- everest-operator.v0.0.0
- everest-operator.v0.9.0
name: fast-v1
package: everest-operator
- schema: olm.channel
name: stable-v0
entries:
schema: olm.channel
- entries:
- name: everest-operator.v0.9.0
- name: everest-operator.v0.9.1
skips:
- everest-operator.v0.9.0
name: stable-v0
package: everest-operator
- schema: olm.bundle
image: docker.io/perconalab/everest-operator-bundle:0.0.0
schema: olm.channel
- image: docker.io/perconalab/everest-operator-bundle:0.0.0
schema: olm.bundle
schema: olm.template.basic
94 changes: 94 additions & 0 deletions tools/everest_basic_template.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package main

import (
"encoding/json"
"fmt"
"github.com/operator-framework/operator-registry/alpha/declcfg"
"github.com/operator-framework/operator-registry/alpha/template/basic"
"gopkg.in/yaml.v3"
"os"
)

const versionPrefix = "everest-operator.v"

type EverestBasicTemplate struct {
basic.BasicTemplate
}

func (t *EverestBasicTemplate) readFromFile(veneerFile string) error {
yamlFile, err := os.ReadFile(veneerFile)
if err != nil {
return err
}

var yamlData interface{}
err = yaml.Unmarshal(yamlFile, &yamlData)
if err != nil {
return err
}

jsonData, err := json.Marshal(yamlData)
if err != nil {
return err
}

return json.Unmarshal(jsonData, t)
}

func (t *EverestBasicTemplate) toByteArray() ([]byte, error) {
bytes, err := json.Marshal(t)
if err != nil {
return nil, err
}
var jsonInterface interface{}
err = json.Unmarshal(bytes, &jsonInterface)
if err != nil {
return nil, err
}
return yaml.Marshal(jsonInterface)
}

func (t *EverestBasicTemplate) update(release release, channel string) error {
for i, meta := range t.Entries {
if meta.Schema == declcfg.SchemaChannel && meta.Name == channel {
bytes, err := updateBlob(meta.Blob, release, channel)
if err != nil {
return fmt.Errorf("failed to update channel data %s", channel)
}
t.Entries[i].Blob.UnmarshalJSON(bytes)
break
}
}

bundle, err := release.bundle()
if err != nil {
return fmt.Errorf("failed to create new bundle: %w", err)
}
t.Entries = append(t.Entries, bundle)
return nil
}

func updateBlob(channelBlob json.RawMessage, release release, channel string) ([]byte, error) {
var ch declcfg.Channel
err := json.Unmarshal(channelBlob, &ch)
if err != nil {
return nil, fmt.Errorf("error unmarshaling channel %s: %w", channel, err)
}

if len(ch.Entries) == 0 {
return nil, fmt.Errorf("versions list is empty for %s channel", channel)
}
lastVersion := ch.Entries[len(ch.Entries)-1]
// new version inherits the replaces from the last version and adds a new skip to the skips
newVersion := declcfg.ChannelEntry{
Name: versionPrefix + release.newVersion.String(),
Replaces: lastVersion.Replaces,
Skips: append(lastVersion.Skips, lastVersion.Name),
}
// the previous version shouldn't have any replaces and skips anymore
ch.Entries[len(ch.Entries)-1].Replaces = ""
ch.Entries[len(ch.Entries)-1].Skips = nil
// add the new version to the list of versions
ch.Entries = append(ch.Entries, newVersion)
return json.Marshal(ch)
}
139 changes: 139 additions & 0 deletions tools/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
module github.com/percona/everest-catalog

go 1.22.4

require (
github.com/hashicorp/go-version v1.7.0
github.com/operator-framework/operator-registry v1.44.0
github.com/spf13/cobra v1.8.1
github.com/stretchr/testify v1.9.0
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 // indirect
github.com/BurntSushi/toml v1.3.2 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/Microsoft/hcsshim v0.12.3 // indirect
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230305170008-8188dc5388df // indirect
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/containerd/cgroups/v3 v3.0.3 // indirect
github.com/containerd/containerd v1.7.18 // indirect
github.com/containerd/continuity v0.4.2 // indirect
github.com/containerd/errdefs v0.1.0 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/containerd/ttrpc v1.2.4 // indirect
github.com/containerd/typeurl/v2 v2.1.1 // indirect
github.com/containers/common v0.59.1 // indirect
github.com/containers/image/v5 v5.31.1 // indirect
github.com/containers/libtrust v0.0.0-20230121012942-c1716e8a8d01 // indirect
github.com/containers/ocicrypt v1.1.10 // indirect
github.com/containers/storage v1.54.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/distribution/reference v0.6.0 // indirect
github.com/docker/cli v27.0.2+incompatible // indirect
github.com/docker/distribution v2.8.3+incompatible // indirect
github.com/docker/docker v26.1.3+incompatible // indirect
github.com/docker/docker-credential-helpers v0.8.1 // indirect
github.com/docker/go-connections v0.5.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/emicklei/go-restful/v3 v3.11.2 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.5.0 // indirect
github.com/go-git/go-git/v5 v5.11.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-migrate/migrate/v4 v4.17.1 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/cel-go v0.17.8 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/mux v1.8.1 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 // indirect
github.com/h2non/filetype v1.1.3 // indirect
github.com/h2non/go-is-svg v0.0.0-20160927212452-35e8c4b0612c // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/joelanford/ignore v0.1.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.8 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-sqlite3 v1.14.22 // indirect
github.com/moby/locker v1.0.1 // indirect
github.com/moby/sys/mountinfo v0.7.1 // indirect
github.com/moby/sys/sequential v0.5.0 // indirect
github.com/moby/sys/user v0.1.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/onsi/gomega v1.33.1 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0 // indirect
github.com/opencontainers/runtime-spec v1.2.0 // indirect
github.com/operator-framework/api v0.26.0 // indirect
github.com/otiai10/copy v1.14.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.19.0 // indirect
github.com/prometheus/client_model v0.6.0 // indirect
github.com/prometheus/common v0.51.1 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stoewer/go-strcase v1.3.0 // indirect
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 // indirect
go.etcd.io/bbolt v1.3.10 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.23.1 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.23.1 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/sdk v1.23.1 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
go.opentelemetry.io/proto/otlp v1.1.0 // indirect
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/oauth2 v0.20.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/term v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240318140521-94a12d6c2237 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda // indirect
google.golang.org/grpc v1.64.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
k8s.io/api v0.30.2 // indirect
k8s.io/apiextensions-apiserver v0.30.2 // indirect
k8s.io/apimachinery v0.30.2 // indirect
k8s.io/apiserver v0.30.2 // indirect
k8s.io/client-go v0.30.2 // indirect
k8s.io/component-base v0.30.2 // indirect
k8s.io/klog/v2 v2.120.1 // indirect
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect
k8s.io/utils v0.0.0-20240102154912-e7106e64919e // indirect
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.29.0 // indirect
sigs.k8s.io/controller-runtime v0.18.4 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)
Loading

0 comments on commit f8142bf

Please sign in to comment.