Skip to content

Commit

Permalink
Implement ProjectQuota controller (#253)
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha authored Sep 29, 2023
1 parent cc2b58d commit 122eab1
Show file tree
Hide file tree
Showing 58 changed files with 23,213 additions and 4,392 deletions.
19 changes: 12 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ require (
kmodules.xyz/client-go v0.25.37
kmodules.xyz/custom-resources v0.25.2
kmodules.xyz/go-containerregistry v0.0.11
kmodules.xyz/monitoring-agent-api v0.25.3
kmodules.xyz/resource-metadata v0.17.20-0.20230925104037-c526b22982fe
kmodules.xyz/resource-metrics v0.25.2
kmodules.xyz/monitoring-agent-api v0.25.4
kmodules.xyz/resource-metadata v0.17.20
kmodules.xyz/resource-metrics v0.25.3
kmodules.xyz/sets v0.25.0
kubeops.dev/scanner v0.0.13-0.20230610152531-83d060ed8780
kubepack.dev/lib-helm v0.7.2
Expand All @@ -59,7 +59,7 @@ require (

require (
cloud.google.com/go/compute v1.13.0 // indirect
cloud.google.com/go/compute/metadata v0.2.1 // indirect
cloud.google.com/go/compute/metadata v0.2.2 // indirect
cloud.google.com/go/monitoring v1.8.0 // indirect
cloud.google.com/go/trace v1.4.0 // indirect
contrib.go.opencensus.io/exporter/ocagent v0.7.0 // indirect
Expand All @@ -84,7 +84,7 @@ require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/census-instrumentation/opencensus-proto v0.3.0 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/containerd/stargz-snapshotter/estargz v0.12.1 // indirect
github.com/coreos/go-semver v0.3.0 // indirect
github.com/coreos/go-systemd/v22 v22.4.0 // indirect
Expand Down Expand Up @@ -162,6 +162,7 @@ require (
github.com/prometheus/prometheus v0.35.0 // indirect
github.com/prometheus/statsd_exporter v0.22.7 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/rogpeppe/go-internal v1.8.0 // indirect
github.com/sergi/go-diff v1.2.0 // indirect
github.com/shopspring/decimal v1.2.0 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
Expand Down Expand Up @@ -223,20 +224,24 @@ require (
k8s.io/cli-runtime v0.25.3 // indirect
k8s.io/component-helpers v0.25.1 // indirect
k8s.io/utils v0.0.0-20221108210102-8e77b1f39fe2 // indirect
kmodules.xyz/offshoot-api v0.25.0 // indirect
kmodules.xyz/offshoot-api v0.25.4 // indirect
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.33 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/kustomize/api v0.12.1 // indirect
sigs.k8s.io/kustomize/kyaml v0.13.9 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
)

replace sigs.k8s.io/controller-runtime => github.com/kmodules/controller-runtime v0.13.1-0.20230725210630-f8273f9c4412
replace github.com/imdario/mergo => github.com/imdario/mergo v0.3.6

replace github.com/Masterminds/sprig/v3 => github.com/gomodules/sprig/v3 v3.2.3-0.20220405051441-0a8a99bac1b8

replace helm.sh/helm/v3 => github.com/x-helm/helm/v3 v3.10.2-0.20230910175645-ad538d5bfc73

replace k8s.io/apiserver => github.com/kmodules/apiserver v0.25.2-0.20230817060727-aa2afd31b825

replace sigs.k8s.io/controller-runtime => github.com/kmodules/controller-runtime v0.13.1-0.20230725210630-f8273f9c4412

replace (
github.com/open-policy-agent/gatekeeper => github.com/open-policy-agent/gatekeeper v3.11.0+incompatible
go.opencensus.io => go.opencensus.io v0.23.0
Expand Down
122 changes: 66 additions & 56 deletions go.sum

Large diffs are not rendered by default.

13 changes: 11 additions & 2 deletions pkg/apiserver/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
identityv1alpha1 "kubeops.dev/ui-server/apis/identity/v1alpha1"
policyinstall "kubeops.dev/ui-server/apis/policy/install"
policyapi "kubeops.dev/ui-server/apis/policy/v1alpha1"
projectquotacontroller "kubeops.dev/ui-server/pkg/controllers/projectquota"
"kubeops.dev/ui-server/pkg/graph"
"kubeops.dev/ui-server/pkg/metricshandler"
"kubeops.dev/ui-server/pkg/registry"
Expand Down Expand Up @@ -90,6 +91,7 @@ import (
promclient "kmodules.xyz/monitoring-agent-api/client"
rscoreinstall "kmodules.xyz/resource-metadata/apis/core/install"
rscoreapi "kmodules.xyz/resource-metadata/apis/core/v1alpha1"
mgmtinstall "kmodules.xyz/resource-metadata/apis/management/install"
rsinstall "kmodules.xyz/resource-metadata/apis/meta/install"
rsapi "kmodules.xyz/resource-metadata/apis/meta/v1alpha1"
uiinstall "kmodules.xyz/resource-metadata/apis/ui/install"
Expand All @@ -114,6 +116,7 @@ func init() {
rsinstall.Install(Scheme)
uiinstall.Install(Scheme)
rscoreinstall.Install(Scheme)
mgmtinstall.Install(Scheme)
crdinstall.Install(Scheme)
utilruntime.Must(scannerscheme.AddToScheme(Scheme))
utilruntime.Must(chartsapi.AddToScheme(Scheme))
Expand Down Expand Up @@ -210,7 +213,7 @@ func (c completedConfig) New(ctx context.Context) (*UIServer, error) {
return nil, fmt.Errorf("unable to start manager, reason: %v", err)
}
ctrlClient := mgr.GetClient()
disco, err := kubernetes.NewForConfig(mgr.GetConfig())
disco, err := kubernetes.NewForConfig(cfg)
if err != nil {
return nil, fmt.Errorf("unable to create discovery client, reason: %v", err)
}
Expand All @@ -234,7 +237,13 @@ func (c completedConfig) New(ctx context.Context) (*UIServer, error) {
return nil, err
}

if err := mgr.Add(manager.RunnableFunc(graph.PollNewResourceTypes(cfg))); err != nil {
pqr, err := projectquotacontroller.NewReconciler(mgr.GetClient(), disco).SetupWithManager(mgr)
if err != nil {
klog.Error(err, "unable to create controller", "controller", "ProjectQuota")
os.Exit(1)
}

if err := mgr.Add(manager.RunnableFunc(graph.PollNewResourceTypes(cfg, pqr))); err != nil {
setupLog.Error(err, "unable to set up resource poller")
os.Exit(1)
}
Expand Down
Loading

0 comments on commit 122eab1

Please sign in to comment.