Skip to content

Commit

Permalink
Support network Operator SDK v1.3 deployment
Browse files Browse the repository at this point in the history
In Mellanox/network-operator#86, the network operator updates the
operator SDK to v1.3, which break the CI. This patch fixes the break
in the CI and support the new and old ways of deploying the operator.
  • Loading branch information
root authored and abdallahyas committed Feb 3, 2021
1 parent 92fbdb3 commit ec2a208
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 69 deletions.
32 changes: 13 additions & 19 deletions common/clean_common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export ARTIFACTS=$WORKSPACE/artifacts
export KUBECONFIG=${KUBECONFIG:-/etc/kubernetes/admin.conf}

source ./common/common_functions.sh
source ./common/nic_operator_common.sh

function delete_pods {
kubectl delete pods --all
Expand Down Expand Up @@ -194,36 +195,29 @@ function get_service_log {
}

function delete_nic_operator_namespace {
local nic_operator_namespace_dir=$WORKSPACE/mellanox-network-operator/deploy/
local nic_operator_namespace_file=$nic_operator_namespace_dir/operator-ns.yaml
let status=0

if [[ ! -f "$nic_operator_namespace_file" ]];then
echo "$nic_operator_namespace_file not found!!"
echo "Assuming CI did not start."
return 0
fi
kubectl delete namespace "$NIC_OPERATOR_RESOURCES_NAMESPACE"
let status=$status+$?

for file in $(find $nic_operator_namespace_dir -type f -name *-ns.yaml);do
kubectl delete -f "$file"
sleep 30
done
kubectl delete namespace "$NIC_OPERATOR_NAMESPACE"
let status=$status+$?

return $status
}

function delete_nic_cluster_policies {
local nic_operator_crds_dir=$WORKSPACE/mellanox-network-operator/deploy/crds/
local nic_cluster_policy_file=$(find $nic_operator_crds_dir -type f -name *nicclusterpolicies_crd.yaml)

if [[ ! -f "$nic_cluster_policy_file" ]];then
echo "No $nic_cluster_policy_file found, assuming CI did not start!"
local nic_cluster_policy_name="$NIC_OPERATOR_CRD_NAME"

if [[ -z "$(kubectl get crds | grep $nic_cluster_policy_name)" ]];then
echo "No CRD named $nic_cluster_policy_name found, assuming CI did not start!"
return 0
fi

local nic_cluster_policy_name=$(yaml_read metadata.name "$nic_cluster_policy_file")
local resources_namespace=$(yaml_read metadata.name ${nic_operator_crds_dir}/../operator-resources-ns.yaml)

kubectl delete $nic_cluster_policy_name --all --wait=true

asure_resource_deleted "pods" "$resources_namespace"
asure_resource_deleted "pods" "$NIC_OPERATOR_RESOURCES_NAMESPACE"

load_core_drivers
sleep 5
Expand Down
11 changes: 3 additions & 8 deletions common/nic_operator_common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export SRIOV_INTERFACE=${SRIOV_INTERFACE:-auto_detect}

export MACVLAN_NETWORK_DEFAULT_NAME=${MACVLAN_NETWORK_DEFAULT_NAME:-'example-macvlan'}
export NIC_OPERATOR_NAMESPACE=${NIC_OPERATOR_NAMESPACE:-'mlnx-network-operator'}
export NIC_OPERATOR_RESOURCES_NAMESPACE=${NIC_OPERATOR_RESOURCES_NAMESPACE:-'mlnx-network-operator-resources'}

export nic_operator_dir=$WORKSPACE/mellanox-network-operator/

Expand Down Expand Up @@ -41,7 +42,7 @@ export SECONDARY_NETWORK_IPAM_PLUGIN_REPO=${SECONDARY_NETWORK_IPAM_PLUGIN_REPO:-
export SECONDARY_NETWORK_IPAM_PLUGIN_VERSION=${SECONDARY_NETWORK_IPAM_PLUGIN_VERSION:-'latest'}

export NIC_OPERATOR_HELM_NAME=${NIC_OPERATOR_HELM_NAME:-'network-operator-helm-ci'}
NIC_OPERATOR_CRD_FILE=$nic_operator_dir/deploy/crds/mellanox.com_nicclusterpolicies_crd.yaml
export NIC_OPERATOR_CRD_NAME=${NIC_OPERATOR_CRD_NAME:-'nicclusterpolicies.mellanox.com'}

function configure_macvlan_custom_resource {
local file_name="$1"
Expand Down Expand Up @@ -125,9 +126,7 @@ function verfiy_module {
return 1
fi

operator_resourses_namespace=$(yaml_read metadata.name ${nic_operator_dir}/deploy/operator-resources-ns.yaml)

ofed_module=$(kubectl exec -n $operator_resourses_namespace $ofed_pod_name -- modinfo $module | grep srcversion | cut -d':' -f 2 | tr -d ' ')
ofed_module=$(kubectl exec -n $NIC_OPERATOR_RESOURCES_NAMESPACE $ofed_pod_name -- modinfo $module | grep srcversion | cut -d':' -f 2 | tr -d ' ')
if [[ -z "$ofed_module" ]];then
echo "Error: couldn't get the ofed module signture!!"
return 1
Expand All @@ -150,8 +149,6 @@ function get_nic_policy_state {

local lower_state_name="$(tr [:upper:] [:lower:] <<< $state_name)"

NIC_OPERATOR_CRD_NAME=$(yq r $NIC_OPERATOR_CRD_FILE metadata.name)

local nic_policy_status=$(kubectl get "$NIC_OPERATOR_CRD_NAME" \
-n "$NIC_OPERATOR_NAMESPACE" "$resource_name" -o yaml)

Expand All @@ -177,8 +174,6 @@ function wait_nic_policy_states {
local state_key=${2:-state}
local wanted_state=${3:-ready}

NIC_OPERATOR_CRD_NAME=$(yq r $NIC_OPERATOR_CRD_FILE metadata.name)

cr_status="$(get_nic_policy_state $cr_name $state_key)"
let stop=$(date '+%s')+$TIMEOUT
d=$(date '+%s')
Expand Down
71 changes: 41 additions & 30 deletions nic_operator/nic_operator_ci_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function download_and_build {
return $?
}


function configure_namespace {
local namespace=$1

Expand All @@ -48,39 +49,51 @@ function configure_namespace {

}


function deploy_operator_components {
let status=0
pushd $WORKSPACE/mellanox-network-operator/deploy

yaml_write spec.template.spec.containers[0].image 'mellanox/network-operator' operator.yaml
let status=status+$?

yaml_write spec.template.spec.containers[0].imagePullPolicy 'IfNotPresent' operator.yaml
let status=status+$?

kubectl create -f operator-resources-ns.yaml
let status=status+$?

kubectl create -f operator-ns.yaml
let status=status+$?

kubectl create -f service_account.yaml
let status=status+$?

kubectl create -f role.yaml
let status=status+$?

kubectl create -f role_binding.yaml
let status=status+$?

for file in $(find ./crds/ -type f -name *_crd.yaml);do
kubectl apply -f "$file"
if [[ ! -d $WORKSPACE/mellanox-network-operator/config ]];then

configure_namespace mlnx-network-operator

pushd $WORKSPACE/mellanox-network-operator/deploy

yaml_write spec.template.spec.containers[0].image 'mellanox/network-operator' operator.yaml
let status=status+$?
sleep 2
done

yaml_write spec.template.spec.containers[0].imagePullPolicy 'IfNotPresent' operator.yaml
let status=status+$?

kubectl create -f operator-resources-ns.yaml
let status=status+$?

kubectl create -f operator-ns.yaml
let status=status+$?

kubectl create -f service_account.yaml
let status=status+$?

kubectl create -f role.yaml
let status=status+$?

kubectl create -f role_binding.yaml
let status=status+$?

for file in $(find ./crds/ -type f -name *_crd.yaml);do
kubectl apply -f "$file"
let status=status+$?
sleep 2
done

kubectl create -f operator.yaml
let status=status+$?
else
pushd $WORKSPACE/mellanox-network-operator

kubectl create -f operator.yaml
let status=status+$?
make deploy
let status=status+$?
fi

if [ "$status" != 0 ]; then
echo "Failed to deploy operator componentes"
Expand Down Expand Up @@ -146,8 +159,6 @@ function main {
exit 1
fi

configure_namespace mlnx-network-operator

deploy_operator_components
if [ $? -ne 0 ]; then
echo "Failed to run the operator components"
Expand Down
19 changes: 7 additions & 12 deletions nic_operator/nic_operator_ci_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ export MACVLAN_NETWORK_DEFAULT_NAME='example-macvlan'

export CNI_BIN_DIR=${CNI_BIN_DIR:-'/opt/cni/bin'}

nic_operator_dir=$WORKSPACE/mellanox-network-operator/deploy

source ./common/common_functions.sh
source ./common/clean_common.sh
source ./common/nic_operator_common.sh
Expand All @@ -32,15 +30,6 @@ function nic_policy_create {
status=0
cr_file="$1"

operator_namespace=$(yaml_read metadata.name ${nic_operator_dir}/deploy/operator-ns.yaml)
if [[ -z "$operator_namespace" ]]; then
echo "Could not find operatore name space in ${nic_operator_dir}/deploy/operator-ns.yaml !!!"
return 1
fi

NIC_OPERATOR_NAMESPACE=$operator_namespace
export NIC_OPERATOR_NAMESPACE

kubectl create -f $cr_file

wait_nic_policy_states "$(yq r $cr_file metadata.name)"
Expand Down Expand Up @@ -268,7 +257,13 @@ function test_secondary_network {
sudo rm -f "${CNI_BIN_DIR}/multus"
sudo rm -f "${CNI_BIN_DIR}/whereabouts"

kubectl create -f $WORKSPACE/mellanox-network-operator/deploy/crds/k8s.cni.cncf.io_networkattachmentdefinitions_crd.yaml
if [[ -d "$WORKSPACE/mellanox-network-operator/config" ]];then
network_attachment_definition_file="$WORKSPACE/mellanox-network-operator/config/crd/bases/k8s.cni.cncf.io_networkattachmentdefinitions_crd.yaml"
else
network_attachment_definition_file="$WORKSPACE/mellanox-network-operator/deploy/crds/k8s.cni.cncf.io_networkattachmentdefinitions_crd.yaml"
fi

kubectl create -f "$network_attachment_definition_file"

unlabel_master

Expand Down

0 comments on commit ec2a208

Please sign in to comment.