Skip to content

Commit

Permalink
Add Gateway kubectl Explain to sqlite
Browse files Browse the repository at this point in the history
  • Loading branch information
weibaohui committed Jul 15, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent bcb62d4 commit 6024dd2
Showing 7 changed files with 56 additions and 37 deletions.
5 changes: 3 additions & 2 deletions BlazorApp/Service/impl/TranslateService.cs
Original file line number Diff line number Diff line change
@@ -155,6 +155,7 @@ await db.Insertable<KubeExplainEN>(new KubeExplainEN[]
{
Id = enId,
Explain = en,
Date = DateTime.Now.ToString("yyyy-MM-dd"),
done = false
}
}).ExecuteCommandAsync();
@@ -195,12 +196,12 @@ private async Task ProcessKubeExplainsCn()
{
Id = cnId,
EnId = en.Id,
Explain = cn
Explain = cn, Date = DateTime.Now.ToString("yyyy-MM-dd")
}).ExecuteCommandAsync();
logger.LogInformation("保存 {Current}/{All} {EnId} {Rest} ", current, all, en.Id, rest);
await db.Updateable(en).ExecuteCommandAsync();

Thread.Sleep(1000);
Thread.Sleep(200);
}
}
}
Binary file modified BlazorApp/docs.db
Binary file not shown.
26 changes: 16 additions & 10 deletions Entity/KubeExplainEntity.cs
Original file line number Diff line number Diff line change
@@ -6,35 +6,41 @@ public class KubeExplainEntity
{
// public string Name { get; set; }
// public string FullName { get; set; }
public string ExplainFiled { get; set; }
public string ExplainFiled { get; set; }
public string ExplainVersion { get; set; }
public string Explain { get; set; }
public string ExplainCN { get; set; }
public string Explain { get; set; }
public string ExplainCN { get; set; }
}

[SugarTable]
public class KubeExplainEN
{
[SugarColumn(IsPrimaryKey = true)] //设置主键
public string Id { get; set; }
public string Id { get; set; }

public string Explain { get; set; }
public bool done { get; set; }
public string Date { get; set; }
public bool done { get; set; }
}

[SugarTable]
public class KubeExplainCN
{

[SugarColumn(IsPrimaryKey = true)] //设置主键
public string Id { get; set; }
public string EnId { get; set; }
public string Id { get; set; }

public string EnId { get; set; }
public string Explain { get; set; }
public string Date { get; set; }
}

[SugarTable]
public class KubeExplainRef
{
[SugarColumn(IsPrimaryKey = true)] //设置主键
public string ExplainFiled { get; set; }
public string EnId { get; set; }
public string CnId { get; set; }

public string EnId { get; set; }
public string CnId { get; set; }
public string Date { get; set; }
}
16 changes: 8 additions & 8 deletions Generator/EntityPrepare.cs
Original file line number Diff line number Diff line change
@@ -23,16 +23,16 @@ public static List<KubeType> GetK8SEntity(Type type, string resourceName)


var list = zList
.Where(x => (x.FieldLevel == 2 || x.FieldLevel == 3)
&& !x.FullName.Contains(".Metadata")
&& !x.FullName.Contains(".ApiVersion")
&& !x.FullName.Contains(".Kind")
)
// .Where(x => (x.FieldLevel == 2 || x.FieldLevel == 3)
// && !x.FullName.Contains(".Metadata")
// && !x.FullName.Contains(".ApiVersion")
// && !x.FullName.Contains(".Kind")
// )
.ToList();

// list = RemoveMultipleItem(list);
// list = RemoveOnlyOneChildItem(list);
// list = RemoveExpandedItem(list);
list = RemoveMultipleItem(list);
list = RemoveOnlyOneChildItem(list);
list = RemoveExpandedItem(list);
File.WriteAllText("pod-zip3.json", KubernetesJson.Serialize(list));
return list;
}
4 changes: 2 additions & 2 deletions Generator/Program.cs
Original file line number Diff line number Diff line change
@@ -56,11 +56,11 @@ private static void MakeTemplate()

public static void Main()
{
MakeTemplate();
// MakeTemplate();
// EntityPrepare.PrepareK8SEntity();
// RazorEngineProcessor.Process();
// Volume();
// kubectExplainGen.Explain();
kubectExplainGen.Explain();
}

public static void Volume()
27 changes: 14 additions & 13 deletions Generator/ReflectHelper.cs
Original file line number Diff line number Diff line change
@@ -15,10 +15,10 @@ public class ReflectHelper<T>
/// <returns></returns>
public static string GetValue(T item, string key)
{
Type type = typeof(T);
var property = type.GetProperty(key);
DynamicMethod method = new DynamicMethod("GetPropertyValue", typeof(object), new Type[] { type }, true);
ILGenerator il = method.GetILGenerator();
Type type = typeof(T);
var property = type.GetProperty(key);
DynamicMethod method = new DynamicMethod("GetPropertyValue", typeof(object), new Type[] { type }, true);
ILGenerator il = method.GetILGenerator();
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Callvirt, property.GetGetMethod());

@@ -28,8 +28,8 @@ public static string GetValue(T item, string key)
}

il.Emit(OpCodes.Ret);
Func<T, object> fun = method.CreateDelegate(typeof(Func<T, object>)) as Func<T, object>;
object value = fun.Invoke(item);
Func<T, object> fun = method.CreateDelegate(typeof(Func<T, object>)) as Func<T, object>;
object value = fun.Invoke(item);
return value.ToString();
}

@@ -53,14 +53,15 @@ public static void ListProperty(Type type, string parentName, IList<KubeType> co
.Replace("`1", "")
.Replace("[", "")
.Replace("]", "");
kt.Name = method?.Name.Replace("get_", "");
kt.FullName = parentName + "." + kt.Name;
kt.Name = method?.Name.Replace("get_", "");
kt.FullName = parentName + "." + kt.Name;
kt.ExplainFiled = kt.FullName.ToCamelCase(true);
kt.FieldLevel = kt.ExplainFiled.CountBy(".") + 1;
kt.IsList = IsList(kt.Type);
kt.IsStatus = kt.FullName.Contains(".Status");
kt.ShowInJson = ShowInJson(kt.Type);
if (kt.Type != null && kt.Type.Contains("k8s"))
kt.FieldLevel = kt.ExplainFiled.CountBy(".") + 1;
kt.IsList = IsList(kt.Type);
kt.IsStatus = kt.FullName.Contains(".Status");
kt.ShowInJson = ShowInJson(kt.Type);
if (kt.Type != null && (kt.Type.Contains("k8s") || kt.Type.Contains("Gateway")))
// if (kt.Type != null )
{
if (kt.IsList)
{
15 changes: 13 additions & 2 deletions Generator/kubectExplainGen.cs
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.IO;
using Entity;
using k8s.Models;
using Entity.Crd.Gateway;
using SqlSugar;

namespace Generator;
@@ -51,7 +51,18 @@ public static void Explain()
// dictList.AddItem("Pod", typeof(V1Pod));
// dictList.AddItem("Lease", typeof(V1Lease));
// dictList.AddItem("Namespace", typeof(V1Namespace));
dictList.AddItem("Event", typeof(Corev1Event));
// dictList.AddItem("Event", typeof(Corev1Event));

dictList.AddItem("GatewayClass", typeof(V1GatewayClass));
dictList.AddItem("Gateway", typeof(V1Gateway));
dictList.AddItem("HttpRoute", typeof(V1HTTPRoute));
dictList.AddItem("GrpcRoute", typeof(V1GRPCRoute));
dictList.AddItem("TcpRoute", typeof(V1Alpha2TCPRoute));
dictList.AddItem("UdpRoute", typeof(V1Alpha2UDPRoute));
dictList.AddItem("TlsRoute", typeof(V1Alpha2TLSRoute));
dictList.AddItem("ReferenceGrant", typeof(V1Alpha2ReferenceGrant));
dictList.AddItem("BackendTLSPolicy", typeof(V1Alpha3BackendTLSPolicy));
dictList.AddItem("BackendLBPolicy", typeof(V1Alpha2BackendLBPolicy));

Console.WriteLine("AddList Over");

0 comments on commit 6024dd2

Please sign in to comment.