forked from submariner-io/submariner
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add SubM operator, tests, e2e integration
Signed-off-by: Daniel Farrell <dfarrell@redhat.com> Signed-off-by: Miguel Angel Ajo Pelayo <majopela@redhat.com> Signed-off-by: Stephen Kitt <skitt@redhat.com> Signed-off-by: Mike Kolesnik <mkolesni@redhat.com> Signed-off-by: Janki Chhatbar <jchhatba@redhat.com>
- Loading branch information
1 parent
3135c04
commit e1bf34a
Showing
45 changed files
with
3,599 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
submariner-engine | ||
submariner-route-agent | ||
.dapper | ||
bin | ||
/bin | ||
dist | ||
output | ||
strongswan | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
## Submariner Operator | ||
|
||
Experimental Submariner Operator. | ||
|
||
### Generating the Operator | ||
|
||
The current (developer-oriented) implementation dynamically generates the | ||
operator. This allows us to consume updates to the underlying best practices of | ||
the Operator SDK. It also results in a clear, working example of how to use the | ||
Operator SDK to create additional operators (perhaps for future parts of | ||
Submariner). | ||
|
||
> cd ../../../ | ||
> make codegen-operator | ||
That will run the operator sourcecode generation logic in ./gen_subm_operator.sh | ||
|
||
### Builiding the operator | ||
|
||
> cd ../../.. | ||
> make build-operator | ||
### Deploying Submariner using the Operator | ||
|
||
After generating the Operator (see docs above), your newly generated operator | ||
is automatically fully integrated into the Submariner CI automation. Simply use | ||
the `deploytool` flag to the standard `make` commands. | ||
|
||
> make ci e2e status=keep deploytool=operator | ||
A large set of verifications for the Operator and the resulting Submariner | ||
deployment will automatically run during and after the deployment. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/bin/bash | ||
set -ex | ||
|
||
version=${1:-dev} | ||
push_image=${2:-false} | ||
|
||
cd $(dirname $0) | ||
|
||
# gen_subm_operator.sh / the operator-sdk does not like vendoring mode we enable by default | ||
export GOFLAGS="" | ||
|
||
if [ ! -d submariner-operator ]; then | ||
./gen_subm_operator.sh | ||
fi | ||
|
||
cd submariner-operator | ||
|
||
go mod vendor | ||
|
||
operator-sdk build quay.io/submariner/submariner-operator:$version --verbose | ||
|
||
if [[ $push_image = true ]]; then | ||
docker push quay.io/submariner/submariner-operator:$version | ||
else | ||
echo "Skipping pushing SubM Operator image to Quay" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: submariner-operator | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
name: submariner-operator | ||
template: | ||
metadata: | ||
labels: | ||
name: submariner-operator | ||
spec: | ||
serviceAccountName: submariner-operator | ||
containers: | ||
- name: submariner-operator | ||
image: submariner-operator:local | ||
command: | ||
- submariner-operator | ||
imagePullPolicy: IfNotPresent | ||
env: | ||
- name: WATCH_NAMESPACE | ||
valueFrom: | ||
fieldRef: | ||
fieldPath: metadata.namespace | ||
- name: POD_NAME | ||
valueFrom: | ||
fieldRef: | ||
fieldPath: metadata.name | ||
- name: OPERATOR_NAME | ||
value: "submariner-operator" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"apiVersion": "v1", | ||
"kind": "Namespace", | ||
"metadata": { | ||
"name": "submariner", | ||
"labels": { | ||
"name": "submariner" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
#!/bin/bash | ||
set -ex | ||
|
||
# Work around https://github.com/operator-framework/operator-sdk/issues/1675 | ||
GOROOT="$(go env GOROOT)" | ||
export GOROOT | ||
export GO111MODULE=on | ||
GOPATH=$HOME/go | ||
|
||
# Rely on the Go proxy to accelerate downloads and avoid problems with | ||
# disappearing repositories | ||
export GOPROXY=https://proxy.golang.org | ||
|
||
version=0.0.1 | ||
op_dir=$GOPATH/src/github.com/submariner-operator/submariner-operator | ||
op_gen_dir=$(pwd) | ||
op_out_dir=$op_gen_dir/submariner-operator | ||
|
||
function setup_prereqs(){ | ||
# NB: There must be a running K8s cluster pointed at by the exported KUBECONFIG | ||
# for operator-sdk to work (although this dependency doesn't make sense) | ||
kind delete cluster || true # make sure any pre-existing cluster is removed, otherwise it fails in dapper | ||
kind create cluster || true | ||
export KUBECONFIG="$(kind get kubeconfig-path --name="kind")" | ||
kubectl config use-context kubernetes-admin@kind | ||
} | ||
|
||
function initialize_subm_operator() { | ||
mkdir -p $op_dir | ||
pushd $op_dir/.. | ||
rm -rf $op_dir | ||
operator-sdk new submariner-operator --verbose | ||
popd | ||
|
||
pushd $op_dir | ||
cat deploy/operator.yaml | ||
sed -i "s|REPLACE_IMAGE|quay.io/submariner/submariner-operator:$version|g" deploy/operator.yaml | ||
cat deploy/operator.yaml | ||
|
||
# Add example SubM namespace definition | ||
cp $op_gen_dir/example_subm_ns.yaml deploy/namespace.yaml | ||
|
||
popd | ||
} | ||
|
||
function add_subm_engine_to_operator() { | ||
pushd $op_dir | ||
api_version=submariner.io/v1alpha1 | ||
kind=Submariner | ||
operator-sdk add api --api-version=$api_version --kind=$kind | ||
|
||
# Define spec fields | ||
types_file=pkg/apis/submariner/v1alpha1/submariner_types.go | ||
sed -i '/SubmarinerSpec struct/a \ \ Count int32 `json:"count"`' $types_file | ||
sed -i '/SubmarinerSpec struct/a \ \ Namespace string `json:"namespace"`' $types_file | ||
sed -i '/SubmarinerSpec struct/a \ \ ClusterCIDR string `json:"clusterCIDR"`' $types_file | ||
sed -i '/SubmarinerSpec struct/a \ \ ServiceCIDR string `json:"serviceCIDR"`' $types_file | ||
sed -i '/SubmarinerSpec struct/a \ \ ClusterID string `json:"clusterID"`' $types_file | ||
sed -i '/SubmarinerSpec struct/a \ \ ColorCodes string `json:"colorCodes,omitempty"`' $types_file | ||
sed -i '/SubmarinerSpec struct/a \ \ Debug bool `json:"debug"`' $types_file | ||
sed -i '/SubmarinerSpec struct/a \ \ NatEnabled bool `json:"natEnabled"`' $types_file | ||
sed -i '/SubmarinerSpec struct/a \ \ Broker string `json:"broker"`' $types_file | ||
sed -i '/SubmarinerSpec struct/a \ \ BrokerK8sApiServer string `json:"brokerK8sApiServer"`' $types_file | ||
sed -i '/SubmarinerSpec struct/a \ \ BrokerK8sApiServerToken string `json:"brokerK8sApiServerToken"`' $types_file | ||
sed -i '/SubmarinerSpec struct/a \ \ BrokerK8sRemoteNamespace string `json:"brokerK8sRemoteNamespace"`' $types_file | ||
sed -i '/SubmarinerSpec struct/a \ \ BrokerK8sCA string `json:"brokerK8sCA"`' $types_file | ||
sed -i '/SubmarinerSpec struct/a \ \ CeIPSecPSK string `json:"ceIPSecPSK"`' $types_file | ||
sed -i '/SubmarinerSpec struct/a \ \ CeIPSecDebug bool `json:"ceIPSecDebug"`' $types_file | ||
sed -i '/SubmarinerSpec struct/a \ \ CeIPSecIKEPort int `json:"ceIPSecIKEPort,omitempty"`' $types_file | ||
sed -i '/SubmarinerSpec struct/a \ \ CeIPSecNATTPort int `json:"ceIPSecNATTPort,omitempty"`' $types_file | ||
sed -i '/SubmarinerSpec struct/a \ \ Repository string `json:"repository,omitempty"`' $types_file | ||
sed -i '/SubmarinerSpec struct/a \ \ Version string `json:"version,omitempty"`' $types_file | ||
|
||
# Define status fields, commented example | ||
# sed -i '/SubmarinerStatus struct/a \ \ PodNames []string `json:"pod_names"`' $types_file | ||
|
||
# Fix formatting of types file | ||
go fmt $types_file | ||
|
||
# Show completed types file | ||
cat $types_file | ||
|
||
# Must rebuild after modifying types file | ||
operator-sdk generate k8s | ||
operator-sdk generate openapi | ||
|
||
operator-sdk add controller --api-version=$api_version --kind=$kind | ||
|
||
controller_file_src=$op_gen_dir/submariner_controller.go.nolint | ||
controller_file_dst=pkg/controller/submariner/submariner_controller.go | ||
cp $controller_file_src $controller_file_dst | ||
|
||
popd | ||
} | ||
|
||
function export_subm_op() { | ||
rm -rf $op_out_dir | ||
cp -a $op_dir/. $op_out_dir/ | ||
} | ||
|
||
# Make sure prereqs are installed | ||
setup_prereqs | ||
|
||
# Create SubM Operator | ||
initialize_subm_operator | ||
add_subm_engine_to_operator | ||
|
||
export_subm_op |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
FROM registry.access.redhat.com/ubi7/ubi-minimal:latest | ||
|
||
ENV OPERATOR=/usr/local/bin/submariner-operator \ | ||
USER_UID=1001 \ | ||
USER_NAME=submariner-operator | ||
|
||
# install operator binary | ||
COPY build/_output/bin/submariner-operator ${OPERATOR} | ||
|
||
COPY build/bin /usr/local/bin | ||
RUN /usr/local/bin/user_setup | ||
|
||
ENTRYPOINT ["/usr/local/bin/entrypoint"] | ||
|
||
USER ${USER_UID} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/sh -e | ||
|
||
# This is documented here: | ||
# https://docs.openshift.com/container-platform/3.11/creating_images/guidelines.html#openshift-specific-guidelines | ||
|
||
if ! whoami &>/dev/null; then | ||
if [ -w /etc/passwd ]; then | ||
echo "${USER_NAME:-submariner-operator}:x:$(id -u):$(id -g):${USER_NAME:-submariner-operator} user:${HOME}:/sbin/nologin" >> /etc/passwd | ||
fi | ||
fi | ||
|
||
exec ${OPERATOR} $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/sh | ||
set -x | ||
|
||
# ensure $HOME exists and is accessible by group 0 (we don't know what the runtime UID will be) | ||
mkdir -p ${HOME} | ||
chown ${USER_UID}:0 ${HOME} | ||
chmod ug+rwx ${HOME} | ||
|
||
# runtime user will need to be able to self-insert in /etc/passwd | ||
chmod g+rw /etc/passwd | ||
|
||
# no need for this script to remain in the image after running | ||
rm $0 |
Oops, something went wrong.