Skip to content

Commit 8baae33

Browse files
author
prakashrj
committed
Initial commit
0 parents  commit 8baae33

Some content is hidden

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

56 files changed

+5266
-0
lines changed

Contribution.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Contributing
2+
3+
When contributing to this repository, please first discuss the change you wish to make via issue,
4+
email, or any other method with the owners of this repository before making a change.
5+
6+
Please note we have a code of conduct, please follow it in all your interactions with the project.
7+
8+
## Pull Request Process
9+
10+
1. Ensure any install or build dependencies are removed before the end of the layer when doing a
11+
build.
12+
2. Never use `fmt.Printf`, `fmt.Println` in code for debugging we use a logger which has `Debug, Warn, Fatal, Info`.
13+
3. Update the README.md with details of changes to the interface, this includes new environment
14+
variables, exposed ports, useful file locations and container parameters.
15+
4. Increase the version numbers in any examples files and the README.md to the new version that this
16+
Pull Request would represent. The versioning scheme we use is [SemVer](http://semver.org/).
17+
5. You may merge the Pull Request in once you have the sign-off of two other developers, or if you
18+
do not have permission to do that, you may request the second reviewer to merge it for you.
19+
6. Always run `make fmt` for formatting code.
20+
21+
## Code of Conduct
22+
23+
### Our Pledge
24+
25+
In the interest of fostering an open and welcoming environment, we as
26+
contributors and maintainers pledge to making participation in our project and
27+
our community a harassment-free experience for everyone, regardless of age, body
28+
size, disability, ethnicity, gender identity and expression, level of experience,
29+
nationality, personal appearance, race, religion, or sexual identity and
30+
orientation.
31+
32+
### Our Standards
33+
34+
Examples of behavior that contributes to creating a positive environment
35+
include:
36+
37+
* Using welcoming and inclusive language
38+
* Being respectful of differing viewpoints and experiences
39+
* Gracefully accepting constructive criticism
40+
* Focusing on what is best for the community
41+
* Showing empathy towards other community members
42+
43+
Examples of unacceptable behavior by participants include:
44+
45+
* The use of sexualized language or imagery and unwelcome sexual attention or
46+
advances
47+
* Trolling, insulting/derogatory comments, and personal or political attacks
48+
* Public or private harassment
49+
* Publishing others' private information, such as a physical or electronic
50+
address, without explicit permission
51+
* Other conduct which could reasonably be considered inappropriate in a
52+
professional setting
53+
54+
### Our Responsibilities
55+
56+
Project maintainers are responsible for clarifying the standards of acceptable
57+
behavior and are expected to take appropriate and fair corrective action in
58+
response to any instances of unacceptable behavior.
59+
60+
Project maintainers have the right and responsibility to remove, edit, or
61+
reject comments, commits, code, wiki edits, issues, and other contributions
62+
that are not aligned to this Code of Conduct, or to ban temporarily or
63+
permanently any contributor for other behaviors that they deem inappropriate,
64+
threatening, offensive, or harmful.
65+
66+
### Scope
67+
68+
This Code of Conduct applies both within project spaces and in public spaces
69+
when an individual is representing the project or its community. Examples of
70+
representing a project or community include using an official project e-mail
71+
address, posting via an official social media account, or acting as an appointed
72+
representative at an online or offline event. Representation of a project may be
73+
further defined and clarified by project maintainers.
74+
75+
### Enforcement
76+
77+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
78+
reported by contacting the project team at [INSERT EMAIL ADDRESS]. All
79+
complaints will be reviewed and investigated and will result in a response that
80+
is deemed necessary and appropriate to the circumstances. The project team is
81+
obligated to maintain confidentiality with regard to the reporter of an incident.
82+
Further details of specific enforcement policies may be posted separately.
83+
84+
Project maintainers who do not follow or enforce the Code of Conduct in good
85+
faith may face temporary or permanent repercussions as determined by other
86+
members of the project's leadership.
87+

LICENCE.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Copyright (c) 2020 Salesforce.com, Inc.
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5+
6+
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7+
8+
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9+
10+
* Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
11+
12+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
GO := go
2+
pkgs = $(shell $(GO) list ./... | grep -v vendor)
3+
4+
build:
5+
@./scripts/build.sh
6+
7+
fmt:
8+
@go fmt $(go list ./... | grep -v _base-operator) &> /dev/null
9+
10+
release : build
11+
@echo ">>> Built release"
12+
@rm -rf build/craft
13+
@mkdir -p build/craft
14+
@cp -r _base-operator bin init build/craft
15+
@cd build ; tar -zcf ../craft.tar.gz craft ; cd ..
16+
17+
.PHONY: build format test check_format

PROJECT

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
domain: my.domain
2+
repo: example
3+
resources:
4+
- group: mygroup
5+
kind: MyResource
6+
version: v1
7+
version: "2"

README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Custom Resource Abstraction Fabrication Tool
2+
3+
__NOTE__: For users of CRAFT, a detailed documentation can be found [here](). This README is primarily aimed for developers.
4+
5+
## Contribution
6+
Please refer [Contribution.md](Contribution.md) before pushing the code. If you wish to make a contribution, create a branch, push your code into the branch and create a PR. For more details, check [this article](https://opensource.com/article/19/7/create-pull-request-github).
7+
8+
## Installing craft and its dependencies
9+
Dependencies for CRAFT are `kustomize` and `kubebuilder`.
10+
11+
Latest CRAFT release can be found [here](). Download the craft.tar.gz file and run the following command:
12+
13+
```
14+
sudo tar -C /usr/local/ -xzf ~/Downloads/craft.tar.gz
15+
export PATH=$PATH:/usr/local/craft/bin
16+
```
17+
18+
In case the file is downloaded somewhere other than Downloads, replace ~/Downloads/craft.tar.gz by the path where you downloaded the file.
19+
20+
## Commands of CRAFT
21+
### craft version
22+
Usage :
23+
```
24+
craft version
25+
```
26+
Displays the information about craft, namely version, revision, build user, build date & time, go version.
27+
28+
### craft init
29+
Usage :
30+
```
31+
craft init
32+
```
33+
Initialises a new project with sample controller.json and resource.json
34+
35+
### craft create
36+
Usage :
37+
```
38+
craft create -c "controller.json" -r "resource.json --podDockerFile "dockerFile" -p
39+
```
40+
Creates operator source code in $GOPATH/src, builds operator.yaml, builds and pushes operator and resource docker images.
41+
42+
#### craft build
43+
Has 3 sub commands, code, deploy and image.
44+
45+
#### build code
46+
Usage:
47+
```
48+
craft build code -c "controller.json" -r "resource.json
49+
```
50+
Creates code in $GOPATH/src/operator.
51+
52+
#### build deploy
53+
Usage:
54+
```
55+
craft build deploy -c "controller.json" -r "resource.json
56+
```
57+
Builds operator.yaml for deployment onto cluster.
58+
59+
#### build image
60+
Usage:
61+
```
62+
craft build image -b -c "controller.json" --podDockerFile "dockerFile"
63+
```
64+
Builds operator and resource docker images.
65+
66+
#### validate
67+
Usage:
68+
```
69+
craft validate -v "operator.yaml"
70+
```
71+
Validates operator.yaml to see if everything is in shape

_base-operator/Dockerfile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Copyright (c) 2020, salesforce.com, inc.
2+
# All rights reserved.
3+
# SPDX-License-Identifier: BSD-3-Clause
4+
# For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
5+
6+
# Build the manager binary
7+
FROM golang:1.13 as builder
8+
9+
WORKDIR /workspace
10+
# Copy the Go Modules manifests
11+
COPY go.mod go.mod
12+
COPY go.sum go.sum
13+
# cache deps before building and copying source so that we don't need to re-download as much
14+
# and so that source changes don't invalidate our downloaded layer
15+
RUN go mod download
16+
17+
# Copy the go source
18+
COPY controller.json controller.json
19+
COPY main.go main.go
20+
COPY reconciler/ reconciler/
21+
COPY api/ api/
22+
COPY controllers/ controllers/
23+
24+
# Build
25+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager main.go
26+
27+
# Use distroless as minimal base image to package the manager binary
28+
# Refer to https://github.com/GoogleContainerTools/distroless for more details
29+
FROM gcr.io/distroless/static:nonroot
30+
WORKDIR /
31+
COPY --from=builder /workspace/controller.json .
32+
COPY --from=builder /workspace/manager .
33+
USER nonroot:nonroot
34+
35+
ENTRYPOINT ["/manager"]

_base-operator/Makefile

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
2+
# Image URL to use all building/pushing image targets
3+
IMG ?= controller:latest
4+
NAMESPACE ?= default
5+
IMAGEPULLSECRETS ?= ''
6+
7+
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
8+
CRD_OPTIONS ?= "crd:trivialVersions=true"
9+
10+
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
11+
ifeq (,$(shell go env GOBIN))
12+
GOBIN=$(shell go env GOPATH)/bin
13+
else
14+
GOBIN=$(shell go env GOBIN)
15+
endif
16+
17+
#namespace =
18+
#secret_name =
19+
#secret_engine =
20+
#docker_registry =
21+
22+
#user = $(shell VAULT_TOKEN=$(VAULT_TOKEN) vault read -address=$(VAULT_ADDR) -field=username $(secret_engine))
23+
#password = $(shell VAULT_TOKEN=$(VAULT_TOKEN) vault read -address=$(VAULT_ADDR) -field=password $(secret_engine))
24+
#server = $(shell VAULT_TOKEN=$(VAULT_TOKEN) vault read -address=$(VAULT_ADDR) -field=server $(secret_engine))
25+
26+
all: manager
27+
28+
# Run tests
29+
test: generate fmt vet manifests
30+
go test ./... -coverprofile cover.out
31+
32+
# Build manager binary
33+
manager: generate fmt vet
34+
go build -o bin/manager main.go
35+
36+
# Run against the configured Kubernetes cluster in ~/.kube/config
37+
run: generate fmt vet manifests
38+
go run ./main.go
39+
40+
# Install CRDs into a cluster
41+
install: manifests
42+
kustomize build config/crd | kubectl apply -f -
43+
44+
# Uninstall CRDs from a cluster
45+
uninstall: manifests
46+
kustomize build config/crd | kubectl delete -f -
47+
48+
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
49+
deploy: manifests
50+
@ kubectl create secret docker-registry --dry-run=true $(secret_name) --docker-server=$(server) --docker-username=$(user) --docker-password=$(password) --namespace=$(namespace) -o yaml > config/manager/secret.yaml
51+
52+
cd config/manager && kustomize edit set image controller=${IMG} && kustomize edit set namespace ${NAMESPACE}
53+
kustomize build config/default | kubectl apply -f -
54+
55+
# Generate manifests to install an operator
56+
operator: manifests
57+
58+
cd config/manager && kustomize edit set image controller=${IMG}
59+
cd config/default && kustomize edit set namespace ${NAMESPACE}
60+
kustomize build config/default > ${FILE}
61+
62+
63+
# Generate manifests e.g. CRD, RBAC etc.
64+
manifests: controller-gen
65+
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
66+
67+
# Run go fmt against code
68+
fmt:
69+
go fmt ./...
70+
71+
# Run go vet against code
72+
vet:
73+
go vet ./...
74+
75+
# Generate code
76+
generate: controller-gen
77+
$(CONTROLLER_GEN) object:headerFile=./hack/boilerplate.go.txt paths="./..."
78+
79+
# Docker login
80+
docker-login:
81+
@ echo $(password) | docker login $(server) -u $(user) --password-stdin
82+
83+
# Build the docker image
84+
docker-build: test
85+
docker build . -t ${IMG}
86+
87+
# Push the docker image
88+
docker-push:
89+
docker push ${IMG}
90+
91+
# find or download controller-gen
92+
# download controller-gen if necessary
93+
controller-gen:
94+
ifeq (, $(shell which controller-gen))
95+
# @{ \
96+
# set -e ;\
97+
# CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
98+
# cd $$CONTROLLER_GEN_TMP_DIR ;\
99+
# go mod init tmp ;\
100+
# go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.2.4 ;\
101+
# rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
102+
# }
103+
104+
CONTROLLER_GEN=$(GOBIN)/controller-gen
105+
else
106+
CONTROLLER_GEN=$(shell which controller-gen)
107+
endif

0 commit comments

Comments
 (0)