Skip to content

Commit

Permalink
Merge pull request kubevirt#1803 from slintes/operator
Browse files Browse the repository at this point in the history
Integrate KubeVirt Operator
  • Loading branch information
davidvossel authored Jan 11, 2019
2 parents fb9b14b + e387287 commit 6dd9e09
Show file tree
Hide file tree
Showing 703 changed files with 122,186 additions and 1,458 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ deploy:
- _out/manifests/release/kubevirt.yaml
- _out/templates/manifests/release/kubevirt.yaml.j2
- _out/manifests/release/demo-content.yaml
- _out/manifests/release/kubevirt-operator.yaml
- _out/manifests/release/kubevirt-cr.yaml
- _out/templates/manifests/release/kubevirt-operator.yaml.j2
- _out/templates/manifests/release/kubevirt-cr.yaml.j2
prerelease: true
overwrite: true
name: $TRAVIS_TAG
Expand Down
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export GO15VENDOREXPERIMENT := 1

all:
hack/dockerized "./hack/check.sh && KUBEVIRT_VERSION=${KUBEVIRT_VERSION} ./hack/build-go.sh install ${WHAT} && ./hack/build-copy-artifacts.sh ${WHAT} && DOCKER_PREFIX=${DOCKER_PREFIX} DOCKER_TAG=${DOCKER_TAG} ./hack/build-manifests.sh"
hack/dockerized "./hack/check.sh && KUBEVIRT_VERSION=${KUBEVIRT_VERSION} ./hack/build-go.sh install ${WHAT} && ./hack/build-copy-artifacts.sh ${WHAT} && DOCKER_PREFIX=${DOCKER_PREFIX} DOCKER_TAG=${DOCKER_TAG} IMAGE_PULL_POLICY=${IMAGE_PULL_POLICY} VERBOSITY=${VERBOSITY} ./hack/build-manifests.sh"

generate:
hack/dockerized "./hack/generate.sh"
Expand Down Expand Up @@ -88,4 +88,9 @@ cluster-deploy: cluster-clean

cluster-sync: cluster-build cluster-deploy

cluster-deploy-operator: cluster-clean
./cluster/deploy-operator.sh

cluster-sync-operator: cluster-build cluster-deploy-operator

.PHONY: build test clean distclean checksync sync docker manifests publish functest release-announce cluster-up cluster-down cluster-clean cluster-deploy cluster-sync
2 changes: 1 addition & 1 deletion automation/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ set -e
echo "Nodes are ready:"
kubectl get nodes

make cluster-sync
make cluster-sync-operator

# OpenShift is running important containers under default namespace
namespaces=(kubevirt default)
Expand Down
61 changes: 40 additions & 21 deletions cluster/clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ source hack/config.sh

echo "Cleaning up ..."

# Delete KubeVirt CR, timeout after 10 seconds
set +e
(
cmdpid=$BASHPID
(
sleep 10
kill $cmdpid
) &
_kubectl -n ${namespace} delete kv kubevirt
)
_kubectl -n ${namespace} patch kv kubevirt --type=json -p '[{ "op": "remove", "path": "/metadata/finalizers" }]'

set -e

# Remove finalizers from all running vmis, to not block the cleanup
_kubectl get vmis --all-namespaces -o=custom-columns=NAME:.metadata.name,NAMESPACE:.metadata.namespace,FINALIZERS:.metadata.finalizers --no-headers | grep foregroundDeleteVirtualMachine | while read p; do
arr=($p)
Expand All @@ -35,43 +49,48 @@ done

# Delete all traces of kubevirt
namespaces=(default ${namespace} ${cdi_namespace})
labels=("kubevirt.io" "cdi.kubevirt.io")
labels=("operator.kubevirt.io" "kubevirt.io" "cdi.kubevirt.io")

# Namespaced resources
for i in ${namespaces[@]}; do
for label in ${labels[@]}; do
_kubectl -n ${i} delete deployment -l ${label}
_kubectl -n ${i} delete ds -l ${label}
_kubectl -n ${i} delete rs -l ${label}
_kubectl -n ${i} delete pods -l ${label}
_kubectl -n ${i} delete validatingwebhookconfiguration -l ${label}
_kubectl -n ${i} delete services -l ${label}
_kubectl -n ${i} delete pvc -l ${label}
_kubectl -n ${i} delete pv -l ${label}
_kubectl -n ${i} delete clusterrolebinding -l ${label}
_kubectl -n ${i} delete rolebinding -l ${label}
_kubectl -n ${i} delete roles -l ${label}
_kubectl -n ${i} delete clusterroles -l ${label}
_kubectl -n ${i} delete serviceaccounts -l ${label}
_kubectl -n ${i} delete configmaps -l ${label}
_kubectl -n ${i} delete secrets -l ${label}
_kubectl -n ${i} delete customresourcedefinitions -l ${label}
done
done

if [[ "$KUBEVIRT_PROVIDER" =~ os-* ]]; then
_kubectl -n ${i} delete scc -l ${label}
fi
# Not namespaced resources
for label in ${labels[@]}; do
_kubectl delete validatingwebhookconfiguration -l ${label}
_kubectl delete pv -l ${label}
_kubectl delete clusterrolebinding -l ${label}
_kubectl delete clusterroles -l ${label}
_kubectl delete customresourcedefinitions -l ${label}

# W/A for https://github.com/kubernetes/kubernetes/issues/65818
if [[ "$KUBEVIRT_PROVIDER" =~ .*.10..* ]]; then
# k8s version 1.10.* does not have --wait parameter
_kubectl -n ${i} delete apiservices -l ${label}
else
_kubectl -n ${i} delete apiservices -l ${label} --wait=false
fi
_kubectl -n ${i} get apiservices -l ${label} -o=custom-columns=NAME:.metadata.name,FINALIZERS:.metadata.finalizers --no-headers | grep foregroundDeletion | while read p; do
arr=($p)
name="${arr[0]}"
_kubectl -n ${i} patch apiservices $name --type=json -p '[{ "op": "remove", "path": "/metadata/finalizers" }]'
done
if [[ "$KUBEVIRT_PROVIDER" =~ os-* ]]; then
_kubectl delete scc -l ${label}
fi

# W/A for https://github.com/kubernetes/kubernetes/issues/65818
if [[ "$KUBEVIRT_PROVIDER" =~ .*.10..* ]]; then
# k8s version 1.10.* does not have --wait parameter
_kubectl delete apiservices -l ${label}
else
_kubectl delete apiservices -l ${label} --wait=false
fi
_kubectl get apiservices -l ${label} -o=custom-columns=NAME:.metadata.name,FINALIZERS:.metadata.finalizers --no-headers | grep foregroundDeletion | while read p; do
arr=($p)
name="${arr[0]}"
_kubectl -n ${i} patch apiservices $name --type=json -p '[{ "op": "remove", "path": "/metadata/finalizers" }]'
done
done

Expand Down
55 changes: 55 additions & 0 deletions cluster/deploy-operator.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash
#
# This file is part of the KubeVirt project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Copyright 2018 Red Hat, Inc.
#

set -ex

source hack/common.sh
source cluster/$KUBEVIRT_PROVIDER/provider.sh
source hack/config.sh

echo "Deploying ..."

# Create the installation namespace if it does not exist already
_kubectl apply -f - <<EOF
---
apiVersion: v1
kind: Namespace
metadata:
name: ${namespace}
EOF

# Deploy infra for testing first
_kubectl create -f ${MANIFESTS_OUT_DIR}/testing

# Deploy kubevirt operator
_kubectl apply -f ${MANIFESTS_OUT_DIR}/release/kubevirt-operator.yaml

# Deploy kubevirt
_kubectl create -n ${namespace} -f ${MANIFESTS_OUT_DIR}/release/kubevirt-cr.yaml

if [[ "$KUBEVIRT_PROVIDER" =~ os-* ]]; then
_kubectl create -f ${MANIFESTS_OUT_DIR}/testing/ocp

_kubectl adm policy add-scc-to-user privileged -z kubevirt-operator -n ${namespace}

# Helpful for development. Allows admin to access everything KubeVirt creates in the web console
_kubectl adm policy add-scc-to-user privileged admin
fi

echo "Done"
8 changes: 2 additions & 6 deletions cluster/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,8 @@ EOF
# Deploy infra for testing first
_kubectl create -f ${MANIFESTS_OUT_DIR}/testing

for manifest in ${MANIFESTS_OUT_DIR}/release/*; do
if [[ $manifest =~ .*demo.* ]]; then
continue
fi
_kubectl apply -f $manifest
done
# Deploy kubevirt
_kubectl apply -f ${MANIFESTS_OUT_DIR}/release/kubevirt.yaml

if [[ "$KUBEVIRT_PROVIDER" =~ os-* ]]; then
_kubectl create -f ${MANIFESTS_OUT_DIR}/testing/ocp
Expand Down
2 changes: 1 addition & 1 deletion cluster/ephemeral-provider-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function build() {
done

# Build everyting and publish it
${KUBEVIRT_PATH}hack/dockerized "DOCKER_TAG=${DOCKER_TAG} KUBEVIRT_PROVIDER=${KUBEVIRT_PROVIDER} ./hack/build-manifests.sh"
${KUBEVIRT_PATH}hack/dockerized "DOCKER_PREFIX=${DOCKER_PREFIX} DOCKER_TAG=${DOCKER_TAG} KUBEVIRT_PROVIDER=${KUBEVIRT_PROVIDER} IMAGE_PULL_POLICY=${IMAGE_PULL_POLICY} VERBOSITY=${VERBOSITY} ./hack/build-manifests.sh"
make push

# Make sure that all nodes use the newest images
Expand Down
30 changes: 30 additions & 0 deletions cmd/virt-operator/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#
# This file is part of the KubeVirt project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Copyright 2018 Red Hat, Inc.
#

FROM fedora:28

LABEL maintainer="The KubeVirt Project <[email protected]>"

# Create non-root user
RUN useradd -u 1001 --create-home -s /bin/bash virt-operator
WORKDIR /home/virt-operator
USER 1001
COPY virt-operator /usr/bin/virt-operator
COPY .version /.version

ENTRYPOINT [ "/usr/bin/virt-operator" ]
31 changes: 31 additions & 0 deletions cmd/virt-operator/virt-operator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* This file is part of the KubeVirt project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Copyright 2018 Red Hat, Inc.
*
*/

package main

import (
_ "kubevirt.io/kubevirt/pkg/monitoring/client/prometheus" // import for prometheus metrics
_ "kubevirt.io/kubevirt/pkg/monitoring/reflector/prometheus" // import for prometheus metrics
_ "kubevirt.io/kubevirt/pkg/monitoring/workqueue/prometheus" // import for prometheus metrics
"kubevirt.io/kubevirt/pkg/virt-operator"
)

func main() {
virt_operator.Execute()
}
24 changes: 18 additions & 6 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ import:
version: kubernetes-1.11.2
- package: k8s.io/apiextensions-apiserver
version: kubernetes-1.11.2
- package: github.com/openshift/client-go
version: release-3.11
- package: github.com/fsnotify/fsnotify
version: ^1.4.2
- package: github.com/mailru/easyjson
Expand Down
4 changes: 2 additions & 2 deletions hack/config-default.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
binaries="cmd/virt-controller cmd/virt-launcher cmd/virt-handler cmd/virtctl cmd/fake-qemu-process cmd/virt-api cmd/subresource-access-test cmd/example-hook-sidecar"
docker_images_cacheable="cmd/virt-controller cmd/virt-launcher cmd/virt-handler cmd/virt-api images/disks-images-provider images/vm-killer cmd/subresource-access-test images/winrmcli cmd/example-hook-sidecar images/cdi-http-import-server cmd/container-disk-v1alpha"
binaries="cmd/virt-operator cmd/virt-controller cmd/virt-launcher cmd/virt-handler cmd/virtctl cmd/fake-qemu-process cmd/virt-api cmd/subresource-access-test cmd/example-hook-sidecar"
docker_images_cacheable="cmd/virt-operator cmd/virt-controller cmd/virt-launcher cmd/virt-handler cmd/virt-api images/disks-images-provider images/vm-killer cmd/subresource-access-test images/winrmcli cmd/example-hook-sidecar images/cdi-http-import-server cmd/container-disk-v1alpha"
docker_images_container_disks="images/cirros-container-disk-demo images/fedora-cloud-container-disk-demo images/alpine-container-disk-demo images/virtio-container-disk"
docker_images="${docker_images_cacheable} ${docker_images_container_disks}"
docker_prefix=${DOCKER_PREFIX:-kubevirt}
Expand Down
2 changes: 2 additions & 0 deletions hack/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ ${KUBEVIRT_DIR}/tools/resource-generator/resource-generator --type=vmirs >${KUBE
${KUBEVIRT_DIR}/tools/resource-generator/resource-generator --type=vmipreset >${KUBEVIRT_DIR}/manifests/generated/vmipreset-resource.yaml
${KUBEVIRT_DIR}/tools/resource-generator/resource-generator --type=vm >${KUBEVIRT_DIR}/manifests/generated/vm-resource.yaml
${KUBEVIRT_DIR}/tools/resource-generator/resource-generator --type=vmim >${KUBEVIRT_DIR}/manifests/generated/vmim-resource.yaml
${KUBEVIRT_DIR}/tools/resource-generator/resource-generator --type=kv >${KUBEVIRT_DIR}/manifests/generated/kv-resource.yaml
${KUBEVIRT_DIR}/tools/resource-generator/resource-generator --type=kv-cr --namespace={{.Namespace}} --pullPolicy={{.ImagePullPolicy}} >${KUBEVIRT_DIR}/manifests/generated/kubevirt-cr.yaml.in
${KUBEVIRT_DIR}/tools/resource-generator/resource-generator --type=rbac --namespace={{.Namespace}} >${KUBEVIRT_DIR}/manifests/generated/rbac.authorization.k8s.yaml.in
${KUBEVIRT_DIR}/tools/resource-generator/resource-generator --type=prometheus --namespace={{.Namespace}} >${KUBEVIRT_DIR}/manifests/generated/prometheus.yaml.in
${KUBEVIRT_DIR}/tools/resource-generator/resource-generator --type=virt-api --namespace={{.Namespace}} --repository={{.DockerPrefix}} --version={{.DockerTag}} --pullPolicy={{.ImagePullPolicy}} --verbosity={{.Verbosity}} >${KUBEVIRT_DIR}/manifests/generated/virt-api.yaml.in
Expand Down
8 changes: 8 additions & 0 deletions manifests/generated/kubevirt-cr.yaml.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
apiVersion: kubevirt.io/v1alpha2
kind: KubeVirt
metadata:
name: kubevirt
namespace: {{.Namespace}}
spec:
imagePullPolicy: {{.ImagePullPolicy}}
Loading

0 comments on commit 6dd9e09

Please sign in to comment.