-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPodsForm.cs
More file actions
110 lines (96 loc) · 4.28 KB
/
PodsForm.cs
File metadata and controls
110 lines (96 loc) · 4.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using k8s;
using k8s.Models;
namespace KubernetsClient
{
public partial class PodsForm : Form
{
MainForm formAux;
public PodsForm(MainForm main)
{
InitializeComponent();
formAux = main;
showPods();
}
private void showPods()
{
this.listViewPods.View = View.Details;
this.listViewPods.Columns.Clear();
this.listViewPods.Columns.Add("Name", -2, HorizontalAlignment.Left);
this.listViewPods.Columns.Add("Pod IP", -2, HorizontalAlignment.Left);
this.listViewPods.Columns.Add("Date created", -2, HorizontalAlignment.Left);
this.listViewPods.Columns.Add("", -5, HorizontalAlignment.Left);
}
private void PodsForm_Load(object sender, EventArgs e)
{
listPods();
}
private void listPods()
{
listViewPods.Items.Clear();
var pods = formAux.client.ListNamespacedPod(formAux.namespaceSelected);
foreach (var pod in pods.Items)
{
string[] row = { pod.Metadata.Name, pod.Status.PodIP,/*podStatus(pod),*/ pod.Metadata.CreationTimestamp.ToString() };
var listItem = new ListViewItem(row);
this.listViewPods.Items.Add(listItem);
this.listViewPods.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
}
}
private static string podStatus(V1Pod pod)
{
string typeAux = "";
foreach (var podCondition in pod.Status.Conditions)
{
typeAux = podCondition.Type;
}
return typeAux;
}
private void btnCreatePod_Click(object sender, EventArgs e)
{
string namePod = null;
formAux.InputBox("Pod - Name", "Insert name:", ref namePod);
var pod = new V1Pod { Metadata = new V1ObjectMeta { Labels = new Dictionary<string, string>() { { "app", namePod } }, Name = namePod }, Spec = new V1PodSpec { Containers = new List<V1Container>() { new V1Container { Name = namePod, Image = namePod, ImagePullPolicy = "Always" } }, NodeName = formAux.nodeSelected, HostNetwork = true } };
try { formAux.client.CreateNamespacedPod(pod, formAux.namespaceSelected); } catch { }
listPods();
}
private async void btnDeletePod_Click(object sender, EventArgs e)
{
DialogResult result = MessageBox.Show("Do you want to save changes?", "Confirmation", MessageBoxButtons.YesNo);
if (result == DialogResult.Yes)
{
listViewPods.Items[listViewPods.FocusedItem.Index].SubItems.Add("Deleting .....");
listViewPods.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
var status = formAux.client.DeleteNamespacedPod(listViewPods.FocusedItem.Text, formAux.namespaceSelected, new V1DeleteOptions());
await Task.Delay(8000);
listPods();
MessageBox.Show("Deleted successfuly !");
}
else if (result == DialogResult.No)
{
//...
}
}
private void btnCreateService_Click(object sender, EventArgs e)
{
/* string nameService = null;
string protocol = null;
//formAux.InputBox("Service - Name", "Insert name:", ref nameService);
ServiceInputBox("Service - Create", "Insert name:", ref nameService, ref protocol);
//MessageBox.Show(protocol);
var createService = new V1Service { Metadata = new V1ObjectMeta { Name = nameService }, Spec = new V1ServiceSpec { Selector = new Dictionary<string, string>() { { "app", listBoxListPods.SelectedItem.ToString() } }, Ports = new List<V1ServicePort>() { new V1ServicePort { Protocol = protocol, Port = 80 } } } };
formAux.client.CreateNamespacedService(createService, formAux.namespaceSelected);*/
}
private void btnBack_Click(object sender, EventArgs e)
{
this.Close();
}
}
}