Skip to content

Commit

Permalink
Remove Entities and EntitySources (#413)
Browse files Browse the repository at this point in the history
* Updates codebase to use `catalogmetadata` package

Signed-off-by: Mikalai Radchuk <[email protected]>
Signed-off-by: Daniel Franz<[email protected]>

* Updates resolutioncli to remove entity source

Signed-off-by: Mikalai Radchuk <[email protected]>

* Removes entity sources and GVK related code

* Removes provides+required GVK and associated tests.
  GVK related code was a dead weight since were
  never set GVK properties on bundle entity.

* Remove entity + entitysource and associated util pkgs

Signed-off-by: dtfranz <[email protected]>

* Deppy version bump, remove remaining entity/entitysource vestigials

Signed-off-by: dtfranz <[email protected]>

* Add interface for client mocking

Signed-off-by: dtfranz <[email protected]>

* Fix tests, bump catalogd, address comments.

Signed-off-by: dtfranz <[email protected]>

---------

Signed-off-by: Mikalai Radchuk <[email protected]>
Signed-off-by: Daniel Franz<[email protected]>
Signed-off-by: dtfranz <[email protected]>
Co-authored-by: Mikalai Radchuk <[email protected]>
  • Loading branch information
dtfranz and m1kola authored Sep 21, 2023
1 parent 6640aac commit 52a1e28
Show file tree
Hide file tree
Showing 40 changed files with 1,341 additions and 2,409 deletions.
10 changes: 6 additions & 4 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ import (
rukpakv1alpha1 "github.com/operator-framework/rukpak/api/v1alpha1"

operatorsv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
catalogclient "github.com/operator-framework/operator-controller/internal/catalogmetadata/client"
"github.com/operator-framework/operator-controller/internal/controllers"
"github.com/operator-framework/operator-controller/internal/resolution/entitysources"
"github.com/operator-framework/operator-controller/pkg/features"
)

Expand Down Expand Up @@ -99,12 +99,14 @@ func main() {
os.Exit(1)
}

cl := mgr.GetClient()
catalogClient := catalogclient.New(cl)

if err = (&controllers.OperatorReconciler{
Client: mgr.GetClient(),
Client: cl,
Scheme: mgr.GetScheme(),
Resolver: solver.NewDeppySolver(
entitysources.NewCatalogdEntitySource(mgr.GetClient()),
controllers.NewVariableSource(mgr.GetClient()),
controllers.NewVariableSource(cl, catalogClient),
),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Operator")
Expand Down
78 changes: 78 additions & 0 deletions cmd/resolutioncli/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
Copyright 2023.
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 main

import (
"context"

"github.com/operator-framework/operator-registry/alpha/action"

"github.com/operator-framework/operator-controller/internal/catalogmetadata"
"github.com/operator-framework/operator-controller/internal/catalogmetadata/client"
)

type indexRefClient struct {
renderer action.Render
bundlesCache []*catalogmetadata.Bundle
}

func newIndexRefClient(indexRef string) *indexRefClient {
return &indexRefClient{
renderer: action.Render{
Refs: []string{indexRef},
AllowedRefMask: action.RefDCImage | action.RefDCDir,
},
}
}

func (c *indexRefClient) Bundles(ctx context.Context) ([]*catalogmetadata.Bundle, error) {
if c.bundlesCache == nil {
cfg, err := c.renderer.Run(ctx)
if err != nil {
return nil, err
}

var (
channels []*catalogmetadata.Channel
bundles []*catalogmetadata.Bundle
)

for i := range cfg.Channels {
channels = append(channels, &catalogmetadata.Channel{
Channel: cfg.Channels[i],
})
}

for i := range cfg.Bundles {
bundles = append(bundles, &catalogmetadata.Bundle{
Bundle: cfg.Bundles[i],
})
}

// TODO: update fake catalog name string to be catalog name once we support multiple catalogs in CLI
catalogName := "offline-catalog"

bundles, err = client.PopulateExtraFields(catalogName, channels, bundles)
if err != nil {
return nil, err
}

c.bundlesCache = bundles
}

return c.bundlesCache, nil
}
109 changes: 0 additions & 109 deletions cmd/resolutioncli/entity_source.go

This file was deleted.

33 changes: 13 additions & 20 deletions cmd/resolutioncli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ import (
catalogd "github.com/operator-framework/catalogd/api/core/v1alpha1"

operatorsv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
"github.com/operator-framework/operator-controller/internal/catalogmetadata"
"github.com/operator-framework/operator-controller/internal/controllers"
olmentity "github.com/operator-framework/operator-controller/internal/resolution/entities"
olmvariables "github.com/operator-framework/operator-controller/internal/resolution/variables"
"github.com/operator-framework/operator-controller/internal/resolution/variablesources"
)
Expand Down Expand Up @@ -108,7 +108,7 @@ func validateFlags(packageName, indexRef string) error {
return nil
}

func run(ctx context.Context, packageName, packageVersion, packageChannel, catalogRef, inputDir string) error {
func run(ctx context.Context, packageName, packageVersion, packageChannel, indexRef, inputDir string) error {
clientBuilder := fake.NewClientBuilder().WithScheme(scheme)

if inputDir != "" {
Expand All @@ -121,11 +121,12 @@ func run(ctx context.Context, packageName, packageVersion, packageChannel, catal
}

cl := clientBuilder.Build()
catalogClient := newIndexRefClient(indexRef)

resolver := solver.NewDeppySolver(
newIndexRefEntitySourceEntitySource(catalogRef),
append(
variablesources.NestedVariableSource{newPackageVariableSource(packageName, packageVersion, packageChannel)},
controllers.NewVariableSource(cl)...,
variablesources.NestedVariableSource{newPackageVariableSource(catalogClient, packageName, packageVersion, packageChannel)},
controllers.NewVariableSource(cl, catalogClient)...,
),
)

Expand All @@ -144,32 +145,24 @@ func resolve(ctx context.Context, resolver *solver.DeppySolver, packageName stri
return "", err
}

bundleEntity, err := getBundleEntityFromSolution(solution, packageName)
bundle, err := bundleFromSolution(solution, packageName)
if err != nil {
return "", err
}

// Get the bundle image reference for the bundle
bundleImage, err := bundleEntity.BundlePath()
if err != nil {
return "", err
}

return bundleImage, nil
return bundle.Image, nil
}

func getBundleEntityFromSolution(solution *solver.Solution, packageName string) (*olmentity.BundleEntity, error) {
func bundleFromSolution(solution *solver.Solution, packageName string) (*catalogmetadata.Bundle, error) {
for _, variable := range solution.SelectedVariables() {
switch v := variable.(type) {
case *olmvariables.BundleVariable:
entityPkgName, err := v.BundleEntity().PackageName()
if err != nil {
return nil, err
}
if packageName == entityPkgName {
return v.BundleEntity(), nil
bundlePkgName := v.Bundle().Package
if packageName == bundlePkgName {
return v.Bundle(), nil
}
}
}
return nil, fmt.Errorf("entity for package %q not found in solution", packageName)
return nil, fmt.Errorf("bundle for package %q not found in solution", packageName)
}
3 changes: 2 additions & 1 deletion cmd/resolutioncli/variable_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ import (
"github.com/operator-framework/operator-controller/internal/resolution/variablesources"
)

func newPackageVariableSource(packageName, packageVersion, packageChannel string) func(inputVariableSource input.VariableSource) (input.VariableSource, error) {
func newPackageVariableSource(catalogClient *indexRefClient, packageName, packageVersion, packageChannel string) func(inputVariableSource input.VariableSource) (input.VariableSource, error) {
return func(inputVariableSource input.VariableSource) (input.VariableSource, error) {
pkgSource, err := variablesources.NewRequiredPackageVariableSource(
catalogClient,
packageName,
variablesources.InVersionRange(packageVersion),
variablesources.InChannel(packageChannel),
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ require (
github.com/Masterminds/semver/v3 v3.2.1
github.com/blang/semver/v4 v4.0.0
github.com/go-logr/logr v1.2.4
github.com/google/go-cmp v0.5.9
github.com/onsi/ginkgo/v2 v2.12.1
github.com/onsi/gomega v1.27.10
github.com/operator-framework/api v0.17.4-0.20230223191600-0131a6301e42
github.com/operator-framework/catalogd v0.6.0
github.com/operator-framework/deppy v0.0.0-20230629133131-bb7b6ae7b266
github.com/operator-framework/deppy v0.0.1
github.com/operator-framework/operator-registry v1.28.0
github.com/operator-framework/rukpak v0.13.0
github.com/spf13/pflag v1.0.5
Expand Down Expand Up @@ -73,6 +72,7 @@ require (
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/cel-go v0.12.6 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect
github.com/google/uuid v1.3.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH
github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk=
github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/j-keck/arping v0.0.0-20160618110441-2cf9dc699c56/go.mod h1:ymszkNOg6tORTn+6F6j+Jc8TOr5osrynvN6ivFWZ2GA=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
Expand Down Expand Up @@ -704,8 +704,8 @@ github.com/operator-framework/api v0.17.4-0.20230223191600-0131a6301e42 h1:d/Pnr
github.com/operator-framework/api v0.17.4-0.20230223191600-0131a6301e42/go.mod h1:l/cuwtPxkVUY7fzYgdust2m9tlmb8I4pOvbsUufRb24=
github.com/operator-framework/catalogd v0.6.0 h1:dSZ54MVSHJ8hcoV7OCRxnk3x4O3ramlyPvvz0vsKYdk=
github.com/operator-framework/catalogd v0.6.0/go.mod h1:I0n086a4a+nP1YZy742IrPaWvOlWu0Mj6qA6j4K96Vg=
github.com/operator-framework/deppy v0.0.0-20230629133131-bb7b6ae7b266 h1:SQEUaAoRWNhr2poLH6z/RsEWZG7PppDWHsr5vAvJkJc=
github.com/operator-framework/deppy v0.0.0-20230629133131-bb7b6ae7b266/go.mod h1:6kgHMeS5vQt3gqWGgJIig1yT5uflBUsCc1orP+I3nbk=
github.com/operator-framework/deppy v0.0.1 h1:PLTtaFGwktPhKuKZkfUruTimrWpyaO3tghbsjs0uMjc=
github.com/operator-framework/deppy v0.0.1/go.mod h1:EV6vnxRodSFRn2TFztfxFhMPGh5QufOhn3tpIP1Z8cc=
github.com/operator-framework/operator-registry v1.28.0 h1:vtmd2WgJxkx7vuuOxW4k5Le/oo0SfonSeJVMU3rKIfk=
github.com/operator-framework/operator-registry v1.28.0/go.mod h1:UYw3uaZyHwHgnczLRYmUqMpgRgP2EfkqOsaR+LI+nK8=
github.com/operator-framework/rukpak v0.13.0 h1:QP0P9ybwtkFpfVOMY9z5v4+vRyBdoqAotv8RP/SZ0hw=
Expand Down Expand Up @@ -801,7 +801,7 @@ github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkU
github.com/spf13/cobra v0.0.2-0.20171109065643-2da4a54c5cee/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE=
github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA=
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
github.com/spf13/pflag v0.0.0-20170130214245-9ff6c6923cff/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.1-0.20171106142849-4c012f6dcd95/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
Expand Down
4 changes: 2 additions & 2 deletions internal/catalogmetadata/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (c *Client) Bundles(ctx context.Context) ([]*catalogmetadata.Bundle, error)
return nil, err
}

bundles, err = populateExtraFields(catalog.Name, channels, bundles)
bundles, err = PopulateExtraFields(catalog.Name, channels, bundles)
if err != nil {
return nil, err
}
Expand All @@ -67,7 +67,7 @@ func fetchCatalogMetadata[T catalogmetadata.Schemas](ctx context.Context, cl cli
return content, nil
}

func populateExtraFields(catalogName string, channels []*catalogmetadata.Channel, bundles []*catalogmetadata.Bundle) ([]*catalogmetadata.Bundle, error) {
func PopulateExtraFields(catalogName string, channels []*catalogmetadata.Channel, bundles []*catalogmetadata.Bundle) ([]*catalogmetadata.Bundle, error) {
bundlesMap := map[string]*catalogmetadata.Bundle{}
for i := range bundles {
bundleKey := fmt.Sprintf("%s-%s", bundles[i].Package, bundles[i].Name)
Expand Down
Loading

0 comments on commit 52a1e28

Please sign in to comment.