Skip to content

Commit 302df44

Browse files
committed
initial commit with scaffolded project
0 parents  commit 302df44

29 files changed

+1473
-0
lines changed

.gitignore

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
# Binaries for programs and plugins
3+
*.exe
4+
*.exe~
5+
*.dll
6+
*.so
7+
*.dylib
8+
bin
9+
10+
# Test binary, build with `go test -c`
11+
*.test
12+
13+
# Output of the go coverage tool, specifically when used with LiteIDE
14+
*.out
15+
16+
# Kubernetes Generated files - skip generated files, except for vendored files
17+
18+
!vendor/**/zz_generated.*
19+
20+
# editor and IDE paraphernalia
21+
.idea
22+
*.swp
23+
*.swo
24+
*~
25+
26+
cmd/azurerator/azurerator

Dockerfile

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Build the manager binary
2+
FROM golang:1.13 as builder
3+
4+
WORKDIR /workspace
5+
# Copy the Go Modules manifests
6+
COPY go.mod go.mod
7+
COPY go.sum go.sum
8+
# cache deps before building and copying source so that we don't need to re-download as much
9+
# and so that source changes don't invalidate our downloaded layer
10+
RUN go mod download
11+
12+
# Copy the go source
13+
COPY main.go main.go
14+
COPY pkg/apis api/
15+
COPY pkg/controllers controllers/
16+
17+
# Build
18+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager main.go
19+
20+
# Use distroless as minimal base image to package the manager binary
21+
# Refer to https://github.com/GoogleContainerTools/distroless for more details
22+
FROM gcr.io/distroless/static:nonroot
23+
WORKDIR /
24+
COPY --from=builder /workspace/manager .
25+
USER nonroot:nonroot
26+
27+
ENTRYPOINT ["/manager"]

Makefile

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
NAME := azurerator
2+
TAG := navikt/${NAME}
3+
IMG := ${TAG}:latest
4+
5+
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
6+
CRD_OPTIONS ?= "crd:trivialVersions=true"
7+
8+
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
9+
ifeq (,$(shell go env GOBIN))
10+
GOBIN=$(shell go env GOPATH)/bin
11+
else
12+
GOBIN=$(shell go env GOBIN)
13+
endif
14+
15+
all: manager
16+
17+
# Run tests
18+
test: generate fmt vet manifests
19+
go test ./... -coverprofile cover.out
20+
21+
# Build manager binary
22+
manager: generate fmt vet
23+
cd cmd/azurerator && go build
24+
25+
# Run against the configured Kubernetes cluster in ~/.kube/config
26+
run: generate fmt vet manifests
27+
go run cmd/azurerator/main.go
28+
29+
# Install CRDs into a cluster
30+
install: manifests
31+
kustomize build config/crd | kubectl apply -f -
32+
33+
# Uninstall CRDs from a cluster
34+
uninstall: manifests
35+
kustomize build config/crd | kubectl delete -f -
36+
37+
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
38+
deploy: manifests
39+
cd config/manager && kustomize edit set image controller=${IMG}
40+
kustomize build config/default | kubectl apply -f -
41+
42+
# Generate manifests e.g. CRD, RBAC etc.
43+
manifests: controller-gen
44+
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
45+
46+
# Run go fmt against code
47+
fmt:
48+
go fmt ./...
49+
50+
# Run go vet against code
51+
vet:
52+
go vet ./...
53+
54+
# Generate code
55+
generate: controller-gen
56+
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
57+
58+
# Build the docker image
59+
docker-build: test
60+
docker build . -t ${IMG} -t ${TAG}:$(shell /bin/cat ./version) -t ${TAG} -t ${NAME} -t ${IMG}
61+
62+
# Push the docker image
63+
docker-push:
64+
docker push ${TAG}:$(shell /bin/cat ./version)
65+
docker push ${IMG}
66+
67+
# find or download controller-gen
68+
# download controller-gen if necessary
69+
controller-gen:
70+
ifeq (, $(shell which controller-gen))
71+
@{ \
72+
set -e ;\
73+
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
74+
cd $$CONTROLLER_GEN_TMP_DIR ;\
75+
go mod init tmp ;\
76+
go get sigs.k8s.io/controller-tools/cmd/[email protected] ;\
77+
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
78+
}
79+
CONTROLLER_GEN=$(GOBIN)/controller-gen
80+
else
81+
CONTROLLER_GEN=$(shell which controller-gen)
82+
endif

PROJECT

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
domain: nais.io
2+
repo: github.com/nais/azureator
3+
resources:
4+
- group: nais.io
5+
kind: AzureAdCredential
6+
version: v1alpha1
7+
version: "2"

cmd/azurerator/main.go

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package main
2+
3+
import (
4+
"flag"
5+
"os"
6+
7+
"k8s.io/apimachinery/pkg/runtime"
8+
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
9+
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
10+
ctrl "sigs.k8s.io/controller-runtime"
11+
"sigs.k8s.io/controller-runtime/pkg/log/zap"
12+
13+
naisiov1alpha1 "github.com/nais/azureator/pkg/apis/v1alpha1"
14+
"github.com/nais/azureator/pkg/controllers"
15+
// +kubebuilder:scaffold:imports
16+
)
17+
18+
var (
19+
scheme = runtime.NewScheme()
20+
setupLog = ctrl.Log.WithName("setup")
21+
)
22+
23+
func init() {
24+
_ = clientgoscheme.AddToScheme(scheme)
25+
26+
_ = naisiov1alpha1.AddToScheme(scheme)
27+
// +kubebuilder:scaffold:scheme
28+
}
29+
30+
func main() {
31+
var metricsAddr string
32+
var enableLeaderElection bool
33+
flag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.")
34+
flag.BoolVar(&enableLeaderElection, "enable-leader-election", false,
35+
"Enable leader election for controller manager. "+
36+
"Enabling this will ensure there is only one active controller manager.")
37+
flag.Parse()
38+
39+
ctrl.SetLogger(zap.New(zap.UseDevMode(true)))
40+
41+
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
42+
Scheme: scheme,
43+
MetricsBindAddress: metricsAddr,
44+
Port: 9443,
45+
LeaderElection: enableLeaderElection,
46+
LeaderElectionID: "43d2b63b.nais.io",
47+
})
48+
if err != nil {
49+
setupLog.Error(err, "unable to start manager")
50+
os.Exit(1)
51+
}
52+
53+
if err = (&controllers.AzureAdCredentialReconciler{
54+
Client: mgr.GetClient(),
55+
Log: ctrl.Log.WithName("controllers").WithName("AzureAdCredential"),
56+
Scheme: mgr.GetScheme(),
57+
}).SetupWithManager(mgr); err != nil {
58+
setupLog.Error(err, "unable to create controller", "controller", "AzureAdCredential")
59+
os.Exit(1)
60+
}
61+
// +kubebuilder:scaffold:builder
62+
63+
setupLog.Info("starting manager")
64+
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
65+
setupLog.Error(err, "problem running manager")
66+
os.Exit(1)
67+
}
68+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
2+
---
3+
apiVersion: apiextensions.k8s.io/v1beta1
4+
kind: CustomResourceDefinition
5+
metadata:
6+
annotations:
7+
controller-gen.kubebuilder.io/version: v0.2.5
8+
creationTimestamp: null
9+
name: azureadcredentials.nais.io
10+
spec:
11+
group: nais.io
12+
names:
13+
kind: AzureAdCredential
14+
listKind: AzureAdCredentialList
15+
plural: azureadcredentials
16+
singular: azureadcredential
17+
scope: Namespaced
18+
validation:
19+
openAPIV3Schema:
20+
description: AzureAdCredential is the Schema for the azureadcredentials API
21+
properties:
22+
apiVersion:
23+
description: 'APIVersion defines the versioned schema of this representation
24+
of an object. Servers should convert recognized schemas to the latest
25+
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
26+
type: string
27+
kind:
28+
description: 'Kind is a string value representing the REST resource this
29+
object represents. Servers may infer this from the endpoint the client
30+
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
31+
type: string
32+
metadata:
33+
type: object
34+
spec:
35+
description: AzureAdCredentialSpec defines the desired state of AzureAdCredential
36+
properties:
37+
preAuthorizedApplications:
38+
items:
39+
description: AzureAdPreAuthorizedApplication describes an application
40+
that are allowed to request an on-behalf-of token for this application
41+
properties:
42+
clientId:
43+
type: string
44+
name:
45+
type: string
46+
type: object
47+
type: array
48+
replyUrls:
49+
items:
50+
description: AzureAdReplyUrl defines the valid reply URLs for callbacks
51+
after OIDC flows for this application
52+
properties:
53+
url:
54+
type: string
55+
type: object
56+
type: array
57+
type: object
58+
status:
59+
description: AzureAdCredentialStatus defines the observed state of AzureAdCredential
60+
type: object
61+
type: object
62+
version: v1alpha1
63+
versions:
64+
- name: v1alpha1
65+
served: true
66+
storage: true
67+
status:
68+
acceptedNames:
69+
kind: ""
70+
plural: ""
71+
conditions: []
72+
storedVersions: []

config/crd/kustomization.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This kustomization.yaml is not intended to be run by itself,
2+
# since it depends on service name and namespace that are out of this kustomize package.
3+
# It should be run by config/default
4+
resources:
5+
- bases/nais.io_azureadcredentials.yaml
6+
# +kubebuilder:scaffold:crdkustomizeresource
7+
8+
# the following config is for teaching kustomize how to do kustomization for CRDs.
9+
configurations:
10+
- kustomizeconfig.yaml

config/crd/kustomizeconfig.yaml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# This file is for teaching kustomize how to substitute name and namespace reference in CRD
2+
nameReference:
3+
- kind: Service
4+
version: v1
5+
fieldSpecs:
6+
- kind: CustomResourceDefinition
7+
group: apiextensions.k8s.io
8+
path: spec/conversion/webhookClientConfig/service/name
9+
10+
namespace:
11+
- kind: CustomResourceDefinition
12+
group: apiextensions.k8s.io
13+
path: spec/conversion/webhookClientConfig/service/namespace
14+
create: false
15+
16+
varReference:
17+
- path: metadata/annotations

config/default/kustomization.yaml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Adds namespace to all resources.
2+
namespace: azurerator-system
3+
4+
# Value of this field is prepended to the
5+
# names of all resources, e.g. a deployment named
6+
# "wordpress" becomes "alices-wordpress".
7+
# Note that it should also match with the prefix (text before '-') of the namespace
8+
# field above.
9+
namePrefix: azurerator-
10+
11+
# Labels to add to all resources and selectors.
12+
#commonLabels:
13+
# someName: someValue
14+
15+
bases:
16+
- ../crd
17+
- ../rbac
18+
- ../manager

config/manager/kustomization.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
resources:
2+
- manager.yaml

config/manager/manager.yaml

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
apiVersion: v1
2+
kind: Namespace
3+
metadata:
4+
labels:
5+
control-plane: controller-manager
6+
name: system
7+
---
8+
apiVersion: apps/v1
9+
kind: Deployment
10+
metadata:
11+
name: controller-manager
12+
namespace: system
13+
labels:
14+
control-plane: controller-manager
15+
spec:
16+
selector:
17+
matchLabels:
18+
control-plane: controller-manager
19+
replicas: 1
20+
template:
21+
metadata:
22+
labels:
23+
control-plane: controller-manager
24+
spec:
25+
containers:
26+
- command:
27+
- /manager
28+
args:
29+
- --enable-leader-election
30+
image: controller:latest
31+
name: manager
32+
resources:
33+
limits:
34+
cpu: 100m
35+
memory: 30Mi
36+
requests:
37+
cpu: 100m
38+
memory: 20Mi
39+
terminationGracePeriodSeconds: 10

0 commit comments

Comments
 (0)