Skip to content

Commit

Permalink
wire in kapp
Browse files Browse the repository at this point in the history
  • Loading branch information
varshaprasad96 committed Feb 9, 2024
1 parent b6e2aba commit 7f3bdd3
Show file tree
Hide file tree
Showing 5 changed files with 254 additions and 3 deletions.
34 changes: 34 additions & 0 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package main

import (
"flag"
"fmt"
"net/http"
"os"
"time"
Expand All @@ -29,8 +30,10 @@ import (
"go.uber.org/zap/zapcore"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/client-go/discovery"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
_ "k8s.io/client-go/plugin/pkg/client/auth"
"k8s.io/client-go/rest"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
Expand All @@ -41,6 +44,7 @@ import (
catalogclient "github.com/operator-framework/operator-controller/internal/catalogmetadata/client"
"github.com/operator-framework/operator-controller/internal/controllers"
"github.com/operator-framework/operator-controller/pkg/features"
carvelv1alpha1 "github.com/vmware-tanzu/carvel-kapp-controller/pkg/apis/kappctrl/v1alpha1"
)

var (
Expand Down Expand Up @@ -123,11 +127,20 @@ func main() {
setupLog.Error(err, "unable to create controller", "controller", "ClusterExtension")
os.Exit(1)
}

hasKappApis, err := HasKappApis(mgr.GetConfig())
// We should probably prefer to proceed with creating BD instead of exiting?
if err != nil {
setupLog.Error(err, "unable to evaluate if App needs to be created")
os.Exit(1)
}

if err = (&controllers.ExtensionReconciler{
Client: cl,
BundleProvider: catalogClient,
Scheme: mgr.GetScheme(),
Resolver: resolver,
HasKappApis: hasKappApis,

Check failure on line 143 in cmd/manager/main.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofmt`-ed with `-s` (gofmt)
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Extension")
os.Exit(1)
Expand All @@ -149,3 +162,24 @@ func main() {
os.Exit(1)
}
}


// HasKappApis checks whether the cluster has Kapp APIs installed in the cluster.
// This does not guarentee that the controller is present to reconcile the App CRs.

Check failure on line 168 in cmd/manager/main.go

View workflow job for this annotation

GitHub Actions / lint

`guarentee` is a misspelling of `guarantee` (misspell)
func HasKappApis(config *rest.Config) (bool, error) {
discoveryClient, err := discovery.NewDiscoveryClientForConfig(config)
if err != nil {
return false, fmt.Errorf("creating discovery client: %v", err)
}
apiResourceList, err := discoveryClient.ServerResourcesForGroupVersion(carvelv1alpha1.SchemeGroupVersion.String())
if err != nil {
return false, fmt.Errorf("listing resource APIs: %v", err)
}

for _, resource := range apiResourceList.APIResources {
if resource.Kind == "App" {
return true, nil
}
}
return false, nil
}
11 changes: 11 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ rules:
- patch
- update
- watch
- apiGroups:
- kappctrl.k14s.io
resources:
- apps
verbs:
- create
- get
- list
- patch
- update
- watch
- apiGroups:
- olm.operatorframework.io
resources:
Expand Down
6 changes: 5 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module github.com/operator-framework/operator-controller

go 1.20
go 1.21

toolchain go1.21.0

require (
github.com/Masterminds/semver/v3 v3.2.1
Expand All @@ -13,6 +15,7 @@ require (
github.com/operator-framework/rukpak v0.17.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.4
github.com/vmware-tanzu/carvel-kapp-controller v0.50.0
go.uber.org/zap v1.26.0
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
gopkg.in/yaml.v2 v2.4.0
Expand Down Expand Up @@ -117,6 +120,7 @@ require (
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 // indirect
github.com/ulikunitz/xz v0.5.11 // indirect
github.com/vbatts/tar-split v0.11.5 // indirect
github.com/vmware-tanzu/carvel-vendir v0.36.0 // indirect
go.etcd.io/bbolt v1.3.8 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1 // indirect
Expand Down
Loading

0 comments on commit 7f3bdd3

Please sign in to comment.