func (tc *testContext) waitForWindowsNodes(nodeCount int32, expectError, checkVersion bool, isBYOH bool) error {
	annotations := []string{nodeconfig.HybridOverlaySubnet, nodeconfig.HybridOverlayMac, nodeconfig.VersionAnnotation,
		nodeconfig.PubKeyHashAnnotation}
	var creationTime time.Duration
	startTime := time.Now()
	if expectError {
		if nodeCount == 0 {
			creationTime = time.Minute * 10
		} else {
			// The time we expect to wait, if the windowsLabel is
			// not used while creating nodes.
			creationTime = time.Minute * 5
		}
	} else {
		creationTime = nodeCreationTime
	}

	pubKey, err := tc.getExpectedPublicKey()
	if err != nil {
		return errors.Wrap(err, "error getting the expected public key")
	}
	pubKeyAnnotation := nodeconfig.CreatePubKeyHashAnnotation(pubKey)

	// We are waiting 20 minutes for each windows VM to be shown up in the cluster. The value comes from
	// nodeCreationTime variable.  If we are testing a scale down from n nodes to 0, then we should
	// not take the number of nodes into account. If we are testing node creation without applying Windows label, we
	// should throw error within 5 mins.
	err = wait.Poll(nodeRetryInterval, time.Duration(math.Max(float64(nodeCount), 1))*creationTime, func() (done bool, err error) {
		// TODO: vSphere CSRs are not being approved due to a hostname mismatch. This is an issue only because the
		//       ConfigMap controller does not have the ability to approve CSRs yet. This needs to be removed when that
		//       functionality is added in https://issues.redhat.com/browse/WINC-581
		if tc.CloudProvider.GetType() == config.VSpherePlatformType {
			if err := tc.approveAllCSRs(); err != nil {
				log.Printf("error approving CSRs: %s", err)
				return false, nil
			}
		}
		nodes, err := tc.listFullyConfiguredWindowsNodes(isBYOH)
		if err != nil {
			log.Printf("failed to get list of configured Windows nodes: %s", err)
			return false, nil
		}

		for _, node := range nodes {
			// check node status
			readyCondition := false
			for _, condition := range node.Status.Conditions {
				if condition.Type == v1.NodeReady {
					readyCondition = true
				}
				if readyCondition && condition.Status != v1.ConditionTrue {
					log.Printf("node %v is expected to be in Ready state", node.Name)
					return false, nil
				}
			}
			if !readyCondition {
				log.Printf("expected node Status to have condition type Ready for node %v", node.Name)
				return false, nil
			}
			if node.Spec.Unschedulable {
				log.Printf("expected node %s to be schedulable", node.Name)
				return false, nil
			}

			for _, annotation := range annotations {
				_, found := node.Annotations[annotation]
				if !found {
					log.Printf("node %s does not have annotation: %s", node.GetName(), annotation)
					return false, nil
				}
			}
			if checkVersion {
				operatorVersion, err := getWMCOVersion()
				if err != nil {
					log.Printf("error getting operator version : %v", err)
					return false, nil
				}
				if node.Annotations[nodeconfig.VersionAnnotation] != operatorVersion {
					log.Printf("node %s has mismatched version annotation %s. expected: %s", node.GetName(),
						node.Annotations[nodeconfig.VersionAnnotation], operatorVersion)
					return false, nil
				}
			}
			if node.Annotations[nodeconfig.PubKeyHashAnnotation] != pubKeyAnnotation {
				log.Printf("node %s has mismatched pubkey annotation value %s expected: %s", node.GetName(),
					node.Annotations[nodeconfig.PubKeyHashAnnotation], pubKeyAnnotation)
				return false, nil
			}

			// TODO: vSphere CSRs are not being approved due to a hostname mismatch. This is an issue only because the
			//       ConfigMap controller does not have the ability to approve CSRs yet. This can be removed if not
			//       needed when that functionality is added in https://issues.redhat.com/browse/WINC-581
			// verify the node CSR associated with the node is not waiting for approval.
			csr, err := tc.findNodeCSR(node.GetName())
			if err != nil {
				log.Printf("error finding node CSR: %s", err)
				return false, nil
			}
			if tc.isPending(csr) {
				log.Printf("node csr is waiting for approval")
				return false, nil
			}
		}
		// Now verify that we have found all the nodes being waited for
		if len(nodes) != int(nodeCount) {
			log.Printf("waiting for %d/%d Windows nodes", len(nodes), nodeCount)
			return false, nil
		}

		// Initialize/update nodes to avoid staleness
		if isBYOH {
			gc.byohNodes = nodes
		} else {
			gc.machineNodes = nodes
		}
		return true, nil
	})

	// Log the time elapsed while waiting for creation of the nodes
	endTime := time.Now()
	log.Printf("%v time is required to configure %v nodes", endTime.Sub(startTime), nodeCount)

	return err
}
// waitForWindowsNode waits until there exists nodeCount Windows nodes with the correct set of annotations.
// if expectError = true, the function will wait for duration of 10 minutes if we are deleting all nodes i.e. 0 nodesCount
// else 5 minutes for the nodes as the error would be thrown immediately, else we will wait for the duration given by
// nodeCreationTime variable which is 20 minutes increasing the overall wait time in test suite
waitForWindowsNode waits until there exists nodeCount Windows nodes with the correct set of annotations.
if expectError = true, the function will wait for duration of 10 minutes if we are deleting all nodes i.e. 0 nodesCount
else 5 minutes for the nodes as the error would be thrown immediately, else we will wait for the duration given by
nodeCreationTime variable which is 20 minutes increasing the overall wait time in test suite
// waitForWindowsNode waits until there exists nodeCount Windows nodes with the correct set of annotations . // if expectError = true the function will wait for duration of 10 minutes if we are deleting all nodes i . e . 0 nodesCount // else 5 minutes for the nodes as the error would be thrown immediately else we will wait for the duration given by // nodeCreationTime variable which is 20 minutes increasing the overall wait time in test suite
func (tc *testContext) waitForWindowsNodes(nodeCount int32, expectError, checkVersion bool, isBYOH bool) error {
	annotations := []string{nodeconfig.HybridOverlaySubnet, nodeconfig.HybridOverlayMac, nodeconfig.VersionAnnotation,
		nodeconfig.PubKeyHashAnnotation}
	var creationTime time.Duration
	startTime := time.Now()
	if expectError {
		if nodeCount == 0 {
			creationTime = time.Minute * 10
		} else {
			creationTime = time.Minute * 5
		}
	} else {
		creationTime = nodeCreationTime
	}
	pubKey, err := tc.getExpectedPublicKey()
	if err != nil {
		return errors.Wrap(err, "error getting the expected public key")
	}
	pubKeyAnnotation := nodeconfig.CreatePubKeyHashAnnotation(pubKey)
	err = wait.Poll(nodeRetryInterval, time.Duration(math.Max(float64(nodeCount), 1))*creationTime, func() (done bool, err error) {
		if tc.CloudProvider.GetType() == config.VSpherePlatformType {
			if err := tc.approveAllCSRs(); err != nil {
				log.Printf("error approving CSRs: %s", err)
				return false, nil
			}
		}
		nodes, err := tc.listFullyConfiguredWindowsNodes(isBYOH)
		if err != nil {
			log.Printf("failed to get list of configured Windows nodes: %s", err)
			return false, nil
		}
		for _, node := range nodes {
			readyCondition := false
			for _, condition := range node.Status.Conditions {
				if condition.Type == v1.NodeReady {
					readyCondition = true
				}
				if readyCondition && condition.Status != v1.ConditionTrue {
					log.Printf("node %v is expected to be in Ready state", node.Name)
					return false, nil
				}
			}
			if !readyCondition {
				log.Printf("expected node Status to have condition type Ready for node %v", node.Name)
				return false, nil
			}
			if node.Spec.Unschedulable {
				log.Printf("expected node %s to be schedulable", node.Name)
				return false, nil
			}
			for _, annotation := range annotations {
				_, found := node.Annotations[annotation]
				if !found {
					log.Printf("node %s does not have annotation: %s", node.GetName(), annotation)
					return false, nil
				}
			}
			if checkVersion {
				operatorVersion, err := getWMCOVersion()
				if err != nil {
					log.Printf("error getting operator version : %v", err)
					return false, nil
				}
				if node.Annotations[nodeconfig.VersionAnnotation] != operatorVersion {
					log.Printf("node %s has mismatched version annotation %s. expected: %s", node.GetName(),
						node.Annotations[nodeconfig.VersionAnnotation], operatorVersion)
					return false, nil
				}
			}
			if node.Annotations[nodeconfig.PubKeyHashAnnotation] != pubKeyAnnotation {
				log.Printf("node %s has mismatched pubkey annotation value %s expected: %s", node.GetName(),
					node.Annotations[nodeconfig.PubKeyHashAnnotation], pubKeyAnnotation)
				return false, nil
			}
			csr, err := tc.findNodeCSR(node.GetName())
			if err != nil {
				log.Printf("error finding node CSR: %s", err)
				return false, nil
			}
			if tc.isPending(csr) {
				log.Printf("node csr is waiting for approval")
				return false, nil
			}
		}
		if len(nodes) != int(nodeCount) {
			log.Printf("waiting for %d/%d Windows nodes", len(nodes), nodeCount)
			return false, nil
		}
		if isBYOH {
			gc.byohNodes = nodes
		} else {
			gc.machineNodes = nodes
		}
		return true, nil
	})
	endTime := time.Now()
	log.Printf("%v time is required to configure %v nodes", endTime.Sub(startTime), nodeCount)
	return err
}
func ( tc * testContext ) waitForWindowsNodes ( nodeCount int32 , expectError , checkVersion bool , isBYOH bool ) error { annotations := [ ] string { nodeconfig . HybridOverlaySubnet , nodeconfig . HybridOverlayMac , nodeconfig . VersionAnnotation , nodeconfig . PubKeyHashAnnotation } var creationTime time . Duration startTime := time . Now ( ) if expectError { if nodeCount == 0 { creationTime = time . Minute * 10 } else { creationTime = time . Minute * 5 } } else { creationTime = nodeCreationTime } pubKey , err := tc . getExpectedPublicKey ( ) if err != nil { return errors . Wrap ( err , " " ) } pubKeyAnnotation := nodeconfig . CreatePubKeyHashAnnotation ( pubKey ) err = wait . Poll ( nodeRetryInterval , time . Duration ( math . Max ( float64 ( nodeCount ) , 1 ) ) * creationTime , func ( ) ( done bool , err error ) { if tc . CloudProvider . GetType ( ) == config . VSpherePlatformType { if err := tc . approveAllCSRs ( ) ; err != nil { log . Printf ( " " , err ) return false , nil } } nodes , err := tc . listFullyConfiguredWindowsNodes ( isBYOH ) if err != nil { log . Printf ( " " , err ) return false , nil } for _ , node := range nodes { readyCondition := false for _ , condition := range node . Status . Conditions { if condition . Type == v1 . NodeReady { readyCondition = true } if readyCondition && condition . Status != v1 . ConditionTrue { log . Printf ( " " , node . Name ) return false , nil } } if ! readyCondition { log . Printf ( " " , node . Name ) return false , nil } if node . Spec . Unschedulable { log . Printf ( " " , node . Name ) return false , nil } for _ , annotation := range annotations { _ , found := node . Annotations [ annotation ] if ! found { log . Printf ( " " , node . GetName ( ) , annotation ) return false , nil } } if checkVersion { operatorVersion , err := getWMCOVersion ( ) if err != nil { log . Printf ( " " , err ) return false , nil } if node . Annotations [ nodeconfig . VersionAnnotation ] != operatorVersion { log . Printf ( " " , node . GetName ( ) , node . Annotations [ nodeconfig . VersionAnnotation ] , operatorVersion ) return false , nil } } if node . Annotations [ nodeconfig . PubKeyHashAnnotation ] != pubKeyAnnotation { log . Printf ( " " , node . GetName ( ) , node . Annotations [ nodeconfig . PubKeyHashAnnotation ] , pubKeyAnnotation ) return false , nil } csr , err := tc . findNodeCSR ( node . GetName ( ) ) if err != nil { log . Printf ( " " , err ) return false , nil } if tc . isPending ( csr ) { log . Printf ( " " ) return false , nil } } if len ( nodes ) != int ( nodeCount ) { log . Printf ( " " , len ( nodes ) , nodeCount ) return false , nil } if isBYOH { gc . byohNodes = nodes } else { gc . machineNodes = nodes } return true , nil } ) endTime := time . Now ( ) log . Printf ( " " , endTime . Sub ( startTime ) , nodeCount ) return err }
waitForWindowsNode waits until there exists nodeCount Windows nodes with the correct set of annotations.
waitForWindowsNode waits until there exists nodeCount Windows nodes with the correct set of annotations .
// The time we expect to wait, if the windowsLabel is // not used while creating nodes. // We are waiting 20 minutes for each windows VM to be shown up in the cluster. The value comes from // nodeCreationTime variable.  If we are testing a scale down from n nodes to 0, then we should // not take the number of nodes into account. If we are testing node creation without applying Windows label, we // should throw error within 5 mins. // TODO: vSphere CSRs are not being approved due to a hostname mismatch. This is an issue only because the //       ConfigMap controller does not have the ability to approve CSRs yet. This needs to be removed when that //       functionality is added in https://issues.redhat.com/browse/WINC-581 // check node status // TODO: vSphere CSRs are not being approved due to a hostname mismatch. This is an issue only because the //       ConfigMap controller does not have the ability to approve CSRs yet. This can be removed if not //       needed when that functionality is added in https://issues.redhat.com/browse/WINC-581 // verify the node CSR associated with the node is not waiting for approval. // Now verify that we have found all the nodes being waited for // Initialize/update nodes to avoid staleness // Log the time elapsed while waiting for creation of the nodes