Skip to content

Commit 2fdf22b

Browse files
Merge pull request #57 from tg123/intorstr
Add IntOrString support
2 parents 89b23d8 + e599e61 commit 2fdf22b

16 files changed

+167
-31
lines changed

src/IntOrString.cs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using System;
2+
using Newtonsoft.Json;
3+
4+
namespace k8s.Models
5+
{
6+
internal class IntOrStringConverter : JsonConverter
7+
{
8+
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
9+
{
10+
var s = (value as IntOrString)?.Value;
11+
12+
if (int.TryParse(s, out var intv))
13+
{
14+
serializer.Serialize(writer, intv);
15+
return;
16+
}
17+
18+
serializer.Serialize(writer, s);
19+
}
20+
21+
public override object ReadJson(JsonReader reader, Type objectType, object existingValue,
22+
JsonSerializer serializer)
23+
{
24+
return (IntOrString) serializer.Deserialize<string>(reader);
25+
}
26+
27+
public override bool CanConvert(Type objectType)
28+
{
29+
return objectType == typeof(int) || objectType == typeof(string);
30+
}
31+
}
32+
33+
[JsonConverter(typeof(IntOrStringConverter))]
34+
public partial class IntOrString
35+
{
36+
public static implicit operator int(IntOrString v)
37+
{
38+
return int.Parse(v.Value);
39+
}
40+
41+
public static implicit operator IntOrString(int v)
42+
{
43+
return new IntOrString(Convert.ToString(v));
44+
}
45+
46+
public static implicit operator string(IntOrString v)
47+
{
48+
return v.Value;
49+
}
50+
51+
public static implicit operator IntOrString(string v)
52+
{
53+
return new IntOrString(v);
54+
}
55+
}
56+
}

src/generated/Models/Apiappsv1beta1RollingUpdateDeployment.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public Apiappsv1beta1RollingUpdateDeployment()
4848
/// be scaled down further, followed by scaling up the new RC, ensuring
4949
/// that the total number of pods available at all times during the
5050
/// update is at least 70% of desired pods.</param>
51-
public Apiappsv1beta1RollingUpdateDeployment(string maxSurge = default(string), string maxUnavailable = default(string))
51+
public Apiappsv1beta1RollingUpdateDeployment(IntOrString maxSurge = default(IntOrString), IntOrString maxUnavailable = default(IntOrString))
5252
{
5353
MaxSurge = maxSurge;
5454
MaxUnavailable = maxUnavailable;
@@ -74,7 +74,7 @@ public Apiappsv1beta1RollingUpdateDeployment()
7474
/// pods.
7575
/// </summary>
7676
[JsonProperty(PropertyName = "maxSurge")]
77-
public string MaxSurge { get; set; }
77+
public IntOrString MaxSurge { get; set; }
7878

7979
/// <summary>
8080
/// Gets or sets the maximum number of pods that can be unavailable
@@ -89,7 +89,7 @@ public Apiappsv1beta1RollingUpdateDeployment()
8989
/// update is at least 70% of desired pods.
9090
/// </summary>
9191
[JsonProperty(PropertyName = "maxUnavailable")]
92-
public string MaxUnavailable { get; set; }
92+
public IntOrString MaxUnavailable { get; set; }
9393

9494
}
9595
}

src/generated/Models/Apiextensionsv1beta1IngressBackend.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public Apiextensionsv1beta1IngressBackend()
3232
/// service.</param>
3333
/// <param name="servicePort">Specifies the port of the referenced
3434
/// service.</param>
35-
public Apiextensionsv1beta1IngressBackend(string serviceName, string servicePort)
35+
public Apiextensionsv1beta1IngressBackend(string serviceName, IntOrString servicePort)
3636
{
3737
ServiceName = serviceName;
3838
ServicePort = servicePort;
@@ -54,7 +54,7 @@ public Apiextensionsv1beta1IngressBackend(string serviceName, string servicePort
5454
/// Gets or sets specifies the port of the referenced service.
5555
/// </summary>
5656
[JsonProperty(PropertyName = "servicePort")]
57-
public string ServicePort { get; set; }
57+
public IntOrString ServicePort { get; set; }
5858

5959
/// <summary>
6060
/// Validate the object.

src/generated/Models/Apiextensionsv1beta1NetworkPolicyPort.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public Apiextensionsv1beta1NetworkPolicyPort()
3232
/// <param name="protocol">Optional. The protocol (TCP or UDP) which
3333
/// traffic must match. If not specified, this field defaults to
3434
/// TCP.</param>
35-
public Apiextensionsv1beta1NetworkPolicyPort(string port = default(string), string protocol = default(string))
35+
public Apiextensionsv1beta1NetworkPolicyPort(IntOrString port = default(IntOrString), string protocol = default(string))
3636
{
3737
Port = port;
3838
Protocol = protocol;
@@ -51,7 +51,7 @@ public Apiextensionsv1beta1NetworkPolicyPort()
5151
/// only traffic on the specified protocol AND port will be matched.
5252
/// </summary>
5353
[JsonProperty(PropertyName = "port")]
54-
public string Port { get; set; }
54+
public IntOrString Port { get; set; }
5555

5656
/// <summary>
5757
/// Gets or sets optional. The protocol (TCP or UDP) which traffic

src/generated/Models/Apiextensionsv1beta1RollingUpdateDaemonSet.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public Apiextensionsv1beta1RollingUpdateDaemonSet()
4141
/// other DaemonSet pods, thus ensuring that at least 70% of original
4242
/// number of DaemonSet pods are available at all times during the
4343
/// update.</param>
44-
public Apiextensionsv1beta1RollingUpdateDaemonSet(string maxUnavailable = default(string))
44+
public Apiextensionsv1beta1RollingUpdateDaemonSet(IntOrString maxUnavailable = default(IntOrString))
4545
{
4646
MaxUnavailable = maxUnavailable;
4747
CustomInit();
@@ -69,7 +69,7 @@ public Apiextensionsv1beta1RollingUpdateDaemonSet()
6969
/// update.
7070
/// </summary>
7171
[JsonProperty(PropertyName = "maxUnavailable")]
72-
public string MaxUnavailable { get; set; }
72+
public IntOrString MaxUnavailable { get; set; }
7373

7474
}
7575
}

src/generated/Models/Apiextensionsv1beta1RollingUpdateDeployment.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public Apiextensionsv1beta1RollingUpdateDeployment()
4949
/// scaling up the new RC, ensuring that the total number of pods
5050
/// available at all times during the update is at least 70% of desired
5151
/// pods.</param>
52-
public Apiextensionsv1beta1RollingUpdateDeployment(string maxSurge = default(string), string maxUnavailable = default(string))
52+
public Apiextensionsv1beta1RollingUpdateDeployment(IntOrString maxSurge = default(IntOrString), IntOrString maxUnavailable = default(IntOrString))
5353
{
5454
MaxSurge = maxSurge;
5555
MaxUnavailable = maxUnavailable;
@@ -75,7 +75,7 @@ public Apiextensionsv1beta1RollingUpdateDeployment()
7575
/// of desired pods.
7676
/// </summary>
7777
[JsonProperty(PropertyName = "maxSurge")]
78-
public string MaxSurge { get; set; }
78+
public IntOrString MaxSurge { get; set; }
7979

8080
/// <summary>
8181
/// Gets or sets the maximum number of pods that can be unavailable
@@ -90,7 +90,7 @@ public Apiextensionsv1beta1RollingUpdateDeployment()
9090
/// times during the update is at least 70% of desired pods.
9191
/// </summary>
9292
[JsonProperty(PropertyName = "maxUnavailable")]
93-
public string MaxUnavailable { get; set; }
93+
public IntOrString MaxUnavailable { get; set; }
9494

9595
}
9696
}

src/generated/Models/Apinetworkingv1NetworkPolicyPort.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public Apinetworkingv1NetworkPolicyPort()
3232
/// provided, this matches all port names and numbers.</param>
3333
/// <param name="protocol">The protocol (TCP or UDP) which traffic must
3434
/// match. If not specified, this field defaults to TCP.</param>
35-
public Apinetworkingv1NetworkPolicyPort(string port = default(string), string protocol = default(string))
35+
public Apinetworkingv1NetworkPolicyPort(IntOrString port = default(IntOrString), string protocol = default(string))
3636
{
3737
Port = port;
3838
Protocol = protocol;
@@ -50,7 +50,7 @@ public Apinetworkingv1NetworkPolicyPort()
5050
/// this matches all port names and numbers.
5151
/// </summary>
5252
[JsonProperty(PropertyName = "port")]
53-
public string Port { get; set; }
53+
public IntOrString Port { get; set; }
5454

5555
/// <summary>
5656
/// Gets or sets the protocol (TCP or UDP) which traffic must match. If

src/generated/Models/Apipolicyv1beta1PodDisruptionBudgetSpec.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public Apipolicyv1beta1PodDisruptionBudgetSpec()
3939
/// specifying "100%".</param>
4040
/// <param name="selector">Label query over pods whose evictions are
4141
/// managed by the disruption budget.</param>
42-
public Apipolicyv1beta1PodDisruptionBudgetSpec(string maxUnavailable = default(string), string minAvailable = default(string), V1LabelSelector selector = default(V1LabelSelector))
42+
public Apipolicyv1beta1PodDisruptionBudgetSpec(IntOrString maxUnavailable = default(IntOrString), IntOrString minAvailable = default(IntOrString), V1LabelSelector selector = default(V1LabelSelector))
4343
{
4444
MaxUnavailable = maxUnavailable;
4545
MinAvailable = minAvailable;
@@ -60,7 +60,7 @@ public Apipolicyv1beta1PodDisruptionBudgetSpec()
6060
/// exclusive setting with "minAvailable".
6161
/// </summary>
6262
[JsonProperty(PropertyName = "maxUnavailable")]
63-
public string MaxUnavailable { get; set; }
63+
public IntOrString MaxUnavailable { get; set; }
6464

6565
/// <summary>
6666
/// Gets or sets an eviction is allowed if at least "minAvailable" pods
@@ -69,7 +69,7 @@ public Apipolicyv1beta1PodDisruptionBudgetSpec()
6969
/// can prevent all voluntary evictions by specifying "100%".
7070
/// </summary>
7171
[JsonProperty(PropertyName = "minAvailable")]
72-
public string MinAvailable { get; set; }
72+
public IntOrString MinAvailable { get; set; }
7373

7474
/// <summary>
7575
/// Gets or sets label query over pods whose evictions are managed by

src/generated/Models/Corev1HTTPGetAction.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public Corev1HTTPGetAction()
3838
/// <param name="path">Path to access on the HTTP server.</param>
3939
/// <param name="scheme">Scheme to use for connecting to the host.
4040
/// Defaults to HTTP.</param>
41-
public Corev1HTTPGetAction(string port, string host = default(string), IList<Corev1HTTPHeader> httpHeaders = default(IList<Corev1HTTPHeader>), string path = default(string), string scheme = default(string))
41+
public Corev1HTTPGetAction(IntOrString port, string host = default(string), IList<Corev1HTTPHeader> httpHeaders = default(IList<Corev1HTTPHeader>), string path = default(string), string scheme = default(string))
4242
{
4343
Host = host;
4444
HttpHeaders = httpHeaders;
@@ -79,7 +79,7 @@ public Corev1HTTPGetAction()
7979
/// IANA_SVC_NAME.
8080
/// </summary>
8181
[JsonProperty(PropertyName = "port")]
82-
public string Port { get; set; }
82+
public IntOrString Port { get; set; }
8383

8484
/// <summary>
8585
/// Gets or sets scheme to use for connecting to the host. Defaults to

src/generated/Models/Corev1ServicePort.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public Corev1ServicePort()
5050
/// clusterIP=None, and should be omitted or set equal to the 'port'
5151
/// field. More info:
5252
/// https://kubernetes.io/docs/concepts/services-networking/service/#defining-a-service</param>
53-
public Corev1ServicePort(int port, string name = default(string), int? nodePort = default(int?), string protocol = default(string), string targetPort = default(string))
53+
public Corev1ServicePort(int port, string name = default(string), int? nodePort = default(int?), string protocol = default(string), IntOrString targetPort = default(IntOrString))
5454
{
5555
Name = name;
5656
NodePort = nodePort;
@@ -110,7 +110,7 @@ public Corev1ServicePort()
110110
/// https://kubernetes.io/docs/concepts/services-networking/service/#defining-a-service
111111
/// </summary>
112112
[JsonProperty(PropertyName = "targetPort")]
113-
public string TargetPort { get; set; }
113+
public IntOrString TargetPort { get; set; }
114114

115115
/// <summary>
116116
/// Validate the object.
@@ -120,7 +120,6 @@ public Corev1ServicePort()
120120
/// </exception>
121121
public virtual void Validate()
122122
{
123-
//Nothing to validate
124123
}
125124
}
126125
}

0 commit comments

Comments
 (0)