Skip to content

Commit

Permalink
Merge f530583 into 98c4edc
Browse files Browse the repository at this point in the history
  • Loading branch information
awels committed Sep 21, 2020
2 parents 98c4edc + f530583 commit 3e42ef0
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ format:
${DO_BAZ} "./hack/build/format.sh"

manifests:
${DO_BAZ} "DOCKER_PREFIX=${DOCKER_PREFIX} DOCKER_TAG=${DOCKER_TAG} VERBOSITY=${VERBOSITY} PULL_POLICY=${PULL_POLICY} NAMESPACE=${NAMESPACE} ./hack/build/build-manifests.sh"
${DO_BAZ} "DOCKER_PREFIX=${DOCKER_PREFIX} DOCKER_TAG=${DOCKER_TAG} VERBOSITY=${VERBOSITY} PULL_POLICY=${PULL_POLICY} CR_NAME=${CR_NAME} NAMESPACE=${NAMESPACE} ./hack/build/build-manifests.sh"

goveralls: test-unit
${DO} "TRAVIS_JOB_ID=${TRAVIS_JOB_ID} TRAVIS_PULL_REQUEST=${TRAVIS_PULL_REQUEST} TRAVIS_BRANCH=${TRAVIS_BRANCH} ./hack/build/goveralls.sh"
Expand Down
4 changes: 4 additions & 0 deletions automation/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ export CDI_NAMESPACE=$NAMESPACE

echo "namespace: ${NAMESPACE}, cdi-namespace: ${CDI_NAMESPACE}"

if [[ -n "$RANDOM_CR" ]]; then
export CR_NAME="${CDI_NAMESPACE}"
fi

readonly ARTIFACTS_PATH="${ARTIFACTS}"
readonly BAZEL_CACHE="${BAZEL_CACHE:-http://bazel-cache.kubevirt-prow.svc.cluster.local:8080/kubevirt.io/containerized-data-importer}"

Expand Down
2 changes: 1 addition & 1 deletion cluster-sync/clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ if [ -f "${OPERATOR_CR_MANIFEST}" ]; then
echo "Cleaning CR object ..."
if _kubectl get crd cdis.cdi.kubevirt.io ; then
_kubectl delete --ignore-not-found -f "${OPERATOR_CR_MANIFEST}"
_kubectl wait cdis.cdi.kubevirt.io/cdi --for=delete | echo "this is fine"
_kubectl wait cdis.cdi.kubevirt.io/${CR_NAME} --for=delete | echo "this is fine"
fi
fi

Expand Down
2 changes: 1 addition & 1 deletion cluster-sync/sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function wait_cdi_available {
fix_failed_sdn_pods
done
else
_kubectl wait cdis.cdi.kubevirt.io/cdi --for=condition=Available --timeout=${CDI_AVAILABLE_TIMEOUT}s
_kubectl wait cdis.cdi.kubevirt.io/${CR_NAME} --for=condition=Available --timeout=${CDI_AVAILABLE_TIMEOUT}s
fi
}

Expand Down
1 change: 1 addition & 0 deletions hack/build/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ OPERATOR_IMAGE_NAME=${OPERATOR_IMAGE_NAME:-cdi-operator}
DOCKER_TAG=${DOCKER_TAG:-latest}
VERBOSITY=${VERBOSITY:-1}
PULL_POLICY=${PULL_POLICY:-IfNotPresent}
CR_NAME=${CR_NAME:-cdi}
NAMESPACE=${NAMESPACE:-cdi}
CSV_VERSION=${CSV_VERSION:-0.0.0}
QUAY_REPOSITORY=${QUAY_REPOSITORY:-cdi-operatorhub}
Expand Down
1 change: 1 addition & 0 deletions hack/build/resource-generator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ function populateResourceManifest() {
-uploadserver-image="${DOCKER_PREFIX}/${UPLOADSERVER_IMAGE_NAME}:${DOCKER_TAG}" \
-verbosity="${VERBOSITY}" \
-pull-policy="${PULL_POLICY}" \
-cr-name="${CR_NAME}" \
-namespace="${NAMESPACE}" \
-generated-manifests-path=${generatedManifests}
) 1>>"${targetDir}/"$outfile
Expand Down
2 changes: 1 addition & 1 deletion manifests/templates/release/cdi-cr.yaml.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: cdi.kubevirt.io/v1beta1
kind: CDI
metadata:
name: cdi
name: {{.CrName}}
spec:
imagePullPolicy: {{.PullPolicy}}
infra:
Expand Down
12 changes: 7 additions & 5 deletions pkg/controller/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package controller
import (
"context"
"crypto/rsa"
"fmt"
"strings"

sdkapi "github.com/kubevirt/controller-lifecycle-operator-sdk/pkg/sdk/api"
Expand Down Expand Up @@ -462,11 +463,12 @@ func filterCloneSourcePods(input []v1.Pod) []v1.Pod {

// GetWorkloadNodePlacement extracts the workload-specific nodeplacement values from the CDI CR
func GetWorkloadNodePlacement(c client.Client) (*sdkapi.NodePlacement, error) {
cr := &cdiv1.CDI{}
crKey := client.ObjectKey{Namespace: "", Name: "cdi"}
if err := c.Get(context.TODO(), crKey, cr); err != nil {
crList := &cdiv1.CDIList{}
if err := c.List(context.TODO(), crList, &client.ListOptions{}); err != nil {
return nil, err
}

return &cr.Spec.Workloads, nil
if len(crList.Items) != 1 {
return nil, fmt.Errorf("Number of CDI CRs != 1")
}
return &crList.Items[0].Spec.Workloads, nil
}
29 changes: 29 additions & 0 deletions pkg/controller/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"strings"
"testing"

"github.com/kubevirt/controller-lifecycle-operator-sdk/pkg/sdk/api"
. "github.com/onsi/ginkgo"
"github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -144,6 +145,22 @@ var _ = Describe("GetScratchPVCStorageClass", func() {
})
})

var _ = Describe("GetWorkloadNodePlacement", func() {
It("Should return a node placement, with one CDI CR", func() {
client := createClient(createCDIWithWorkload("cdi-test", "1111-1111"))
res, err := GetWorkloadNodePlacement(client)
Expect(err).ToNot(HaveOccurred())
Expect(res).ToNot(BeNil())
})

It("Should return an err with > 1 CDI CR", func() {
client := createClient(createCDIWithWorkload("cdi-test", "1111-1111"), createCDIWithWorkload("cdi-test2", "2222-2222"))
res, err := GetWorkloadNodePlacement(client)
Expect(err).To(HaveOccurred())
Expect(res).To(BeNil())
})
})

func createClient(objs ...runtime.Object) client.Client {
// Register cdi types with the runtime scheme.
s := scheme.Scheme
Expand Down Expand Up @@ -521,3 +538,15 @@ func podUsingPVC(pvc *corev1.PersistentVolumeClaim, readOnly bool) *corev1.Pod {
},
}
}

func createCDIWithWorkload(name, uid string) *cdiv1.CDI {
return &cdiv1.CDI{
ObjectMeta: metav1.ObjectMeta{
Name: name,
UID: types.UID(uid),
},
Spec: cdiv1.CDISpec{
Workloads: api.NodePlacement{},
},
}
}
3 changes: 3 additions & 0 deletions tools/manifest-generator/manifest-generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type templateData struct {
UploadServerImage string
Verbosity string
PullPolicy string
CrName string
Namespace string
GeneratedManifests map[string]string
}
Expand All @@ -60,6 +61,7 @@ var (
uploadServerImage = flag.String("uploadserver-image", "", "")
verbosity = flag.String("verbosity", "1", "")
pullPolicy = flag.String("pull-policy", "", "")
crName = flag.String("cr-name", "", "")
namespace = flag.String("namespace", "", "")
)

Expand Down Expand Up @@ -101,6 +103,7 @@ func generateFromFile(templFile string) {
UploadProxyImage: *uploadProxyImage,
UploadServerImage: *uploadServerImage,
PullPolicy: *pullPolicy,
CrName: *crName,
Namespace: *namespace,
}

Expand Down

0 comments on commit 3e42ef0

Please sign in to comment.