Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request #22 from teodor-pripoae/add-pods-annotations
Browse files Browse the repository at this point in the history
Add pods annotations
  • Loading branch information
moshloop committed May 9, 2020
2 parents 2fa8a7a + 66eef4f commit 7030965
Show file tree
Hide file tree
Showing 32 changed files with 1,457 additions and 258 deletions.
25 changes: 19 additions & 6 deletions .circleci/config.yml
@@ -1,21 +1,34 @@
version: 2
go: &go
environment:
GO111MODULE: "on"
CGO_ENABLED: 0
GOPROXY: https://proxy.golang.org
docker:
- image: circleci/golang:1.12
working_directory: /go/src/github.com/moshloop/platform-operator
jobs:
release:
docker:
- image: circleci/golang:1.12
environment:
GO111MODULE: "on"
working_directory: /go/src/github.com/flanksource/platform-operator
<<: *go
steps:
- checkout
- setup_remote_docker
- run: make ci-release IMG=flanksource/platform-operator TAG=$(date +%Y%m%d%M%H%M%S)
- run: ./scripts/release.sh
test-e2e:
<<: *go
steps:
- checkout
- run: go mod download
- run: ./test/e2e.sh

workflows:
version: 2
build:
jobs:
- test-e2e
- release:
requires:
- test-e2e
context: Github
filters:
tags:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -22,3 +22,6 @@ bin
*.swp
*.swo
*~

.bin
.env
34 changes: 24 additions & 10 deletions cmd/manager/main.go
Expand Up @@ -19,19 +19,21 @@ package main
import (
"flag"
"os"
"strings"
"sync"
"time"

platformv1 "github.com/flanksource/platform-operator/pkg/apis/platform/v1"
"github.com/flanksource/platform-operator/pkg/controllers/cleanup"
"github.com/flanksource/platform-operator/pkg/controllers/clusterresourcequota"
"github.com/flanksource/platform-operator/pkg/controllers/podannotator"
"k8s.io/apimachinery/pkg/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
ctrl "sigs.k8s.io/controller-runtime"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"

platformv1 "github.com/flanksource/platform-operator/pkg/apis/platform/v1"

"github.com/flanksource/platform-operator/pkg/controllers/cleanup"
"github.com/flanksource/platform-operator/pkg/controllers/clusterresourcequota"
"sigs.k8s.io/controller-runtime/pkg/webhook"
// +kubebuilder:scaffold:imports
)

Expand All @@ -50,14 +52,18 @@ func init() {
func main() {
var metricsAddr string
var enableLeaderElection bool
var cleanupInterval time.Duration
var cleanupInterval, annotationInterval time.Duration
var annotations string

flag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.")

flag.BoolVar(&enableLeaderElection, "enable-leader-election", false,
"Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager.")

flag.DurationVar(&cleanupInterval, "cleanup-interval", 10*time.Minute, "Frequency at which the cleanup controller runss.")
flag.DurationVar(&cleanupInterval, "cleanup-interval", 10*time.Minute, "Frequency at which the cleanup controller runs.")
flag.DurationVar(&annotationInterval, "annotation-interval", 10*time.Minute, "Frequency at which the annotation controller runs.")

flag.StringVar(&annotations, "annotations", "", "Annotations pods inherit from parent namespace")

flag.Parse()

Expand All @@ -77,7 +83,7 @@ func main() {
}

// TODO(mazzy89): Make the adding of controllers more dynamic
//

if err := cleanup.Add(mgr, cleanupInterval); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Cleanup")
os.Exit(1)
Expand All @@ -88,13 +94,21 @@ func main() {
os.Exit(1)
}

if err := podannotator.Add(mgr, annotationInterval, strings.Split(annotations, ",")); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "PodAnnotator")
os.Exit(1)
}

// Setup webhooks
setupLog.Info("setting up webhook server")
hookServer := mgr.GetWebhookServer()

mtx := &sync.Mutex{}

setupLog.Info("registering webhooks to the webhook server")
hookServer.Register("/validate-clusterresourcequota-platform-flanksource-com-v1", platformv1.ClusterResourceQuotaValidatingWebhook())
hookServer.Register("/validate-resourcequota-v1", platformv1.ResourceQuotaValidatingWebhook())
hookServer.Register("/mutate-v1-pod", &webhook.Admission{Handler: platformv1.PodAnnotatorMutateWebhook(mgr.GetClient(), strings.Split(annotations, ","))})
hookServer.Register("/validate-clusterresourcequota-platform-flanksource-com-v1", platformv1.ClusterResourceQuotaValidatingWebhook(mtx))
hookServer.Register("/validate-resourcequota-v1", platformv1.ResourceQuotaValidatingWebhook(mtx))

// +kubebuilder:scaffold:builder

Expand Down

0 comments on commit 7030965

Please sign in to comment.