-
Notifications
You must be signed in to change notification settings - Fork 0
/
DeploymentForm.cs
126 lines (110 loc) · 4.67 KB
/
DeploymentForm.cs
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace KubernetsClient
{
public partial class DeploymentForm : Form
{
public MainForm formAux;
public DeploymentForm(MainForm main)
{
InitializeComponent();
formAux = main;
comboBoxReplicas.SelectedIndex = 0;
comboBoxImages.SelectedIndex = 0;
textBoxImage.Hide();
showDeployments();
}
private void showDeployments()
{
this.listViewDeployments.View = View.Details;
this.listViewDeployments.Columns.Clear();
this.listViewDeployments.Columns.Add("Name", -2, HorizontalAlignment.Left);
this.listViewDeployments.Columns.Add("Ready", -2, HorizontalAlignment.Left);
this.listViewDeployments.Columns.Add("Pods Available", -2, HorizontalAlignment.Left);
this.listViewDeployments.Columns.Add("Date created", -2, HorizontalAlignment.Left);
this.listViewDeployments.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
}
private void DeploymentForm_Load(object sender, EventArgs e)
{
listDeployments();
}
private async void listDeployments()
{
listViewDeployments.Items.Clear();
var deployments = await formAux.client.ListNamespacedDeploymentWithHttpMessagesAsync(formAux.namespaceSelected);
foreach (var deployment in deployments.Body.Items)
{
try
{
createListView(deployment.Metadata.Name, deployment.Status.Replicas.Value, deployment.Status.AvailableReplicas.Value, deployment.Status.AvailableReplicas.Value.ToString(), deployment.Metadata.CreationTimestamp.Value);
}
catch { MessageBox.Show("Impossible connect with worker !"); this.Close(); }
}
}
private static string deploymentType(k8s.Models.V1Deployment deployment)
{
string typeAux = "";
foreach (var deploymentCondition in deployment.Status.Conditions)
{
typeAux = deploymentCondition.Type;
}
return typeAux;
}
private void createListView(string name, int ready, int readyAvailable, string status, DateTime age)
{
string ageString = age.ToString();
string readyString = readyAvailable.ToString() + "/" + ready.ToString();
string[] row = { name, readyString, status, ageString };
var listItem = new ListViewItem(row);
this.listViewDeployments.Items.Add(listItem);
this.listViewDeployments.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
}
private void btnCreateDeployment_Click(object sender, EventArgs e)
{
if (checkBoxOther.Checked)
{
if (Int64.Parse(textBoxPort.Text) >= 1 && Int64.Parse(textBoxPort.Text) <= 65534)
{
formAux.createDeployment(textBoxDeploymentName.Text, Int32.Parse(comboBoxReplicas.SelectedItem.ToString()), comboBoxImages.SelectedItem.ToString().ToLower(), textBoxImage.Text.ToLower(), Int32.Parse(comboBoxReplicas.SelectedItem.ToString()));
}
}
else
{
if (Int64.Parse(textBoxPort.Text) >= 1 && Int64.Parse(textBoxPort.Text) <= 65534)
{
formAux.createDeployment(textBoxDeploymentName.Text, Int32.Parse(comboBoxReplicas.SelectedItem.ToString()), comboBoxImages.SelectedItem.ToString().ToLower(), comboBoxImages.SelectedItem.ToString().ToLower(), Int32.Parse(comboBoxReplicas.SelectedItem.ToString()));
}
}
comboBoxImages.Show();
textBoxImage.Hide();
listDeployments();
}
private void btnDeleteDeployment_Click(object sender, EventArgs e)
{
formAux.client.DeleteNamespacedDeploymentWithHttpMessagesAsync(listViewDeployments.FocusedItem.Text, formAux.namespaceSelected);
listDeployments();
}
private void checkBoxOther_CheckedChanged(object sender, EventArgs e)
{
if (checkBoxOther.Checked)
{
comboBoxImages.Hide();
textBoxImage.Show();
}
else
{
comboBoxImages.Show();
textBoxImage.Hide();
}
}
private void btnBack_Click(object sender, EventArgs e)
{
this.Close();
}
}
}