Skip to content

Commit 342eedf

Browse files
committed
First commit, scaffolding
0 parents  commit 342eedf

File tree

106 files changed

+10167
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+10167
-0
lines changed

.gitignore

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
*~

Dockerfile

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Build the manager binary
2+
FROM golang:1.10.3 as builder
3+
4+
# Copy in the go src
5+
WORKDIR /go/src/github.com/replicatedhq/troubleshoot
6+
COPY pkg/ pkg/
7+
COPY cmd/ cmd/
8+
COPY vendor/ vendor/
9+
10+
# Build
11+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager github.com/replicatedhq/troubleshoot/cmd/manager
12+
13+
# Copy the controller-manager into a thin image
14+
FROM ubuntu:latest
15+
WORKDIR /
16+
COPY --from=builder /go/src/github.com/replicatedhq/troubleshoot/manager .
17+
ENTRYPOINT ["/manager"]

Makefile

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
2+
# Image URL to use all building/pushing image targets
3+
IMG ?= controller:latest
4+
5+
all: test manager
6+
7+
# Run tests
8+
test: generate fmt vet manifests
9+
go test ./pkg/... ./cmd/... -coverprofile cover.out
10+
11+
# Build manager binary
12+
manager: generate fmt vet
13+
go build -o bin/manager github.com/replicatedhq/troubleshoot/cmd/manager
14+
15+
# Run against the configured Kubernetes cluster in ~/.kube/config
16+
run: generate fmt vet
17+
go run ./cmd/manager/main.go
18+
19+
# Install CRDs into a cluster
20+
install: manifests
21+
kubectl apply -f config/crds
22+
23+
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
24+
deploy: manifests
25+
kubectl apply -f config/crds
26+
kustomize build config/default | kubectl apply -f -
27+
28+
# Generate manifests e.g. CRD, RBAC etc.
29+
manifests: controller-gen
30+
controller-gen paths=./pkg/apis/...
31+
32+
# Run go fmt against code
33+
fmt:
34+
go fmt ./pkg/... ./cmd/...
35+
36+
# Run go vet against code
37+
vet:
38+
go vet ./pkg/... ./cmd/...
39+
40+
41+
.PHONY: generate
42+
generate: controller-gen client-gen
43+
controller-gen object:headerFile=./hack/boilerplate.go.txt paths=./api/...
44+
client-gen go run ../../vendor/k8s.io/code-generator/cmd/client-gen/main.go --output-package=github.com/replicatedhq/troubleshoot/pkg/client --clientset-name troubleshootclientset --input-base github.com/replicatedhq/troubleshoot/pkg/apis --input troubleshoot/v1beta1 -h ./hack/boilerplate.go.txt
45+
46+
# Build the docker image
47+
docker-build: test
48+
docker build . -t ${IMG}
49+
@echo "updating kustomize image patch file for manager resource"
50+
sed -i'' -e 's@image: .*@image: '"${IMG}"'@' ./config/default/manager_image_patch.yaml
51+
52+
# Push the docker image
53+
docker-push:
54+
docker push ${IMG}
55+
56+
# find or download controller-gen
57+
# download controller-gen if necessary
58+
controller-gen:
59+
ifeq (, $(shell which controller-gen))
60+
go get sigs.k8s.io/controller-tools/cmd/[email protected]
61+
CONTROLLER_GEN=$(shell go env GOPATH)/bin/controller-gen
62+
else
63+
CONTROLLER_GEN=$(shell which controller-gen)
64+
endif
65+
66+
# find or download client-gen
67+
client-gen:
68+
ifeq (, $(shell which client-gen))
69+
go get k8s.io/code-generator/cmd/[email protected]
70+
CLIENT_GEN=$(shell go env GOPATH)/bin/client-gen
71+
else
72+
CLIENT_GEN=$(shell which client-gen)
73+
endif

PROJECT

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version: "1"
2+
domain: replicated.com
3+
repo: github.com/replicatedhq/troubleshoot

cmd/manager/main.go

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
Copyright 2019 Replicated, Inc..
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package main
18+
19+
import (
20+
"flag"
21+
"os"
22+
23+
"github.com/replicatedhq/troubleshoot/pkg/apis"
24+
"github.com/replicatedhq/troubleshoot/pkg/controller"
25+
"github.com/replicatedhq/troubleshoot/pkg/webhook"
26+
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
27+
"sigs.k8s.io/controller-runtime/pkg/client/config"
28+
"sigs.k8s.io/controller-runtime/pkg/manager"
29+
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
30+
"sigs.k8s.io/controller-runtime/pkg/runtime/signals"
31+
)
32+
33+
func main() {
34+
var metricsAddr string
35+
flag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.")
36+
flag.Parse()
37+
logf.SetLogger(logf.ZapLogger(false))
38+
log := logf.Log.WithName("entrypoint")
39+
40+
// Get a config to talk to the apiserver
41+
log.Info("setting up client for manager")
42+
cfg, err := config.GetConfig()
43+
if err != nil {
44+
log.Error(err, "unable to set up client config")
45+
os.Exit(1)
46+
}
47+
48+
// Create a new Cmd to provide shared dependencies and start components
49+
log.Info("setting up manager")
50+
mgr, err := manager.New(cfg, manager.Options{MetricsBindAddress: metricsAddr})
51+
if err != nil {
52+
log.Error(err, "unable to set up overall controller manager")
53+
os.Exit(1)
54+
}
55+
56+
log.Info("Registering Components.")
57+
58+
// Setup Scheme for all resources
59+
log.Info("setting up scheme")
60+
if err := apis.AddToScheme(mgr.GetScheme()); err != nil {
61+
log.Error(err, "unable add APIs to scheme")
62+
os.Exit(1)
63+
}
64+
65+
// Setup all Controllers
66+
log.Info("Setting up controller")
67+
if err := controller.AddToManager(mgr); err != nil {
68+
log.Error(err, "unable to register controllers to the manager")
69+
os.Exit(1)
70+
}
71+
72+
log.Info("setting up webhooks")
73+
if err := webhook.AddToManager(mgr); err != nil {
74+
log.Error(err, "unable to register webhooks to the manager")
75+
os.Exit(1)
76+
}
77+
78+
// Start the Cmd
79+
log.Info("Starting the Cmd.")
80+
if err := mgr.Start(signals.SetupSignalHandler()); err != nil {
81+
log.Error(err, "unable to run the manager")
82+
os.Exit(1)
83+
}
84+
}

0 commit comments

Comments
 (0)