Skip to content

Commit

Permalink
Code comments
Browse files Browse the repository at this point in the history
Signed-off-by: Joe Talerico aka rook <joe.talerico@gmail.com>
  • Loading branch information
jtaleric committed Sep 11, 2024
1 parent c0701a6 commit a4a6ae1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/k8s/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const hostNetServerRole = "host-server"
const hostNetClientRole = "host-client"
const k8sNetperfImage = "quay.io/cloud-bulldozer/k8s-netperf:latest"

// BuildInfra will create the infra for the SUT
func BuildInfra(client *kubernetes.Clientset) error {
_, err := client.CoreV1().Namespaces().Get(context.TODO(), namespace, metav1.GetOptions{})
if err == nil {
Expand Down Expand Up @@ -748,6 +749,7 @@ func GetPods(c *kubernetes.Clientset, dp DeploymentParams) (corev1.PodList, erro
return npl, nil
}

// GetNakedPods when we deploy pods without a higher-level controller like deployment
func GetNakedPods(c *kubernetes.Clientset, label string) (corev1.PodList, error) {
npl := corev1.PodList{}
listOpt := metav1.ListOptions{
Expand Down
8 changes: 8 additions & 0 deletions pkg/k8s/kubevirt.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var (
retry = 30
)

// connect will attempt to connect via ssh to the guest. The VM can take a while for sshkeys to be injected
func connect(config *goph.Config) (*goph.Client, error) {
for i := 0; i < retry; i++ {
client, err := goph.NewConn(config)
Expand All @@ -45,6 +46,7 @@ func connect(config *goph.Config) (*goph.Client, error) {
return nil, fmt.Errorf("Unable to connect via ssh after %d attempts", retry)
}

// SSHConnect sets up the ssh config, then attempts to connect to the VM.
func SSHConnect(conf *config.PerfScenarios) (*goph.Client, error) {
dir, err := os.UserHomeDir()
if err != nil {
Expand Down Expand Up @@ -79,6 +81,7 @@ func SSHConnect(conf *config.PerfScenarios) (*goph.Client, error) {
return client, nil
}

// createCommService creates a SSH nodeport service using port 32022 -> 22
func createCommService(client *kubernetes.Clientset, label map[string]string, name string) error {
log.Infof("🚀 Creating service for %s in namespace %s", name, namespace)
sc := client.CoreV1().Services(namespace)
Expand All @@ -105,6 +108,7 @@ func createCommService(client *kubernetes.Clientset, label map[string]string, na
return err
}

// exposeService will create a route for the ssh nodeport service.
func exposeService(client *kubernetes.Clientset, dynamicClient *dynamic.DynamicClient, svcName string) (string, error) {
gvr := schema.GroupVersionResource{
Group: "route.openshift.io",
Expand Down Expand Up @@ -152,6 +156,7 @@ func exposeService(client *kubernetes.Clientset, dynamicClient *dynamic.DynamicC
return host, nil
}

// CreateVMClient takes in the affinity rules and deploys the VMI
func CreateVMClient(kclient *kubevirtv1.KubevirtV1Client, client *kubernetes.Clientset,
dyn *dynamic.DynamicClient, name string, podAff *corev1.PodAntiAffinity, nodeAff *corev1.NodeAffinity) (string, error) {
label := map[string]string{
Expand Down Expand Up @@ -206,6 +211,7 @@ runcmd:
return host, nil
}

// CreateVMServer will take the pod and node affinity and deploy the VMI
func CreateVMServer(client *kubevirtv1.KubevirtV1Client, name string, role string, podAff corev1.PodAntiAffinity,
nodeAff corev1.NodeAffinity) (*v1.VirtualMachineInstance, error) {
label := map[string]string{
Expand Down Expand Up @@ -249,6 +255,7 @@ runcmd:
return CreateVMI(client, name, label, b64.StdEncoding.EncodeToString([]byte(data)), podAff, nodeAff)
}

// CreateVMI creates the desired Virtual Machine instance with the cloud-init config with affinity.
func CreateVMI(client *kubevirtv1.KubevirtV1Client, name string, label map[string]string, b64data string, podAff corev1.PodAntiAffinity,
nodeAff corev1.NodeAffinity) (*v1.VirtualMachineInstance, error) {
delSeconds := int64(0)
Expand Down Expand Up @@ -321,6 +328,7 @@ func CreateVMI(client *kubevirtv1.KubevirtV1Client, name string, label map[strin
return vmi, nil
}

// WaitForVMI will wait until the resource is in Running state.
func WaitForVMI(client *kubevirtv1.KubevirtV1Client, name string) error {
log.Infof("⏰ Wating for VMI (%s) to be in state running", name)
vmw, err := client.VirtualMachineInstances(namespace).Watch(context.TODO(), metav1.ListOptions{})
Expand Down

0 comments on commit a4a6ae1

Please sign in to comment.