public async Task <int> OnExecuteAsync(CommandLineApplication app) { var crds = GenerateCrds(_resourceLocator).ToList(); var fileWriter = new FileWriter(app.Out); foreach (var crd in crds) { var output = UseOldCrds ? _serializer.Serialize((V1beta1CustomResourceDefinition)crd, Format) : _serializer.Serialize(crd, Format); fileWriter.Add($"{crd.Metadata.Name.Replace('.', '_')}.{Format.ToString().ToLower()}", output); } fileWriter.Add( $"kustomization.{Format.ToString().ToLower()}", _serializer.Serialize( new KustomizationConfig { Resources = crds .Select(crd => $"{crd.Metadata.Name.Replace('.', '_')}.{Format.ToString().ToLower()}") .ToList(), CommonLabels = new Dictionary <string, string> { { "operator-element", "crd" }, }, }, Format)); await fileWriter.OutputAsync(OutputPath); return(ExitCodes.Success); }
public override void Write(FileTemplate fileTemplate, IOutput output) { if (string.IsNullOrEmpty(fileTemplate.Name)) { Logger.Trace("Empty file skipped"); return; } if (fileTemplate.Header.Description != null) { AssemblyName assemblyName = (Assembly.GetEntryAssembly() ?? Assembly.GetCallingAssembly()).GetName(); fileTemplate.Header.Description = string.Format(fileTemplate.Header.Description, $"{assemblyName.Name} {assemblyName.Version}"); } StaticFileTemplate staticFile = fileTemplate as StaticFileTemplate; if (staticFile == null) { throw new NotImplementedException($"The method {nameof(Write)} for type {fileTemplate.GetType().Name} is not implemented in {this.Name}."); } FileWriter fileWriter = new FileWriter(this); fileWriter.Add(fileTemplate.Header) .BreakLine() .Add(staticFile.Content, true); string fileName = FileSystem.Combine(fileTemplate.RelativePath, fileTemplate.Name); output.Write(fileName, fileWriter.ToString()); }
public virtual void Write(FileTemplate fileTemplate, IOutput output) { if (string.IsNullOrEmpty(fileTemplate.Name)) { Logger.Trace("Empty file skipped"); return; } if (fileTemplate.Header.Description != null) { AssemblyName assemblyName = (Assembly.GetEntryAssembly() ?? Assembly.GetCallingAssembly()).GetName(); fileTemplate.Header.Description = string.Format(fileTemplate.Header.Description, $"{assemblyName.Name} {assemblyName.Version}"); } FileWriter writer = new FileWriter(this); this.WriteHeader(fileTemplate, writer); StaticFileTemplate staticFile = fileTemplate as StaticFileTemplate; if (staticFile == null) { this.WriteUsings(fileTemplate, writer); this.Write(fileTemplate.Namespaces, writer); } else { writer.Add(staticFile.Content, true); } string fileName = FileSystem.Combine(fileTemplate.RelativePath, this.FormatFileName(fileTemplate.Name, fileTemplate.IsInterface())); output.Write(fileName, writer.ToString()); }
public async Task <int> OnExecuteAsync(CommandLineApplication app) { var fileWriter = new FileWriter(app.Out); fileWriter.Add( $"namespace.{Format.ToString().ToLower()}", _serializer.Serialize( new V1Namespace( V1Namespace.KubeApiVersion, V1Namespace.KubeKind, new V1ObjectMeta(name: "system")), Format)); fileWriter.Add( $"kustomization.{Format.ToString().ToLower()}", _serializer.Serialize( new KustomizationConfig { NamePrefix = $"{_settings.Name}-", Namespace = $"{_settings.Name}-system", CommonLabels = new Dictionary <string, string> { { "operator", _settings.Name }, }, Resources = new List <string> { $"./namespace.{Format.ToString().ToLower()}", CrdsPath == null || OutputPath == null ? "../crds" : Path.GetRelativePath(OutputPath, CrdsPath).Replace('\\', '/'), RbacPath == null || OutputPath == null ? "../rbac" : Path.GetRelativePath(OutputPath, RbacPath).Replace('\\', '/'), OperatorPath == null || OutputPath == null ? "../operator" : Path.GetRelativePath(OutputPath, OperatorPath).Replace('\\', '/'), }, Images = new List <KustomizationImage> { new() { Name = "operator", NewName = "public-docker-image-path", NewTag = "latest", }, }, },
public async Task <int> OnExecuteAsync(CommandLineApplication app) { var fileWriter = new FileWriter(app.Out); fileWriter.Add( $"operator-role.{Format.ToString().ToLower()}", _serializer.Serialize(GenerateManagerRbac(_resourceLocator), Format)); fileWriter.Add( $"operator-role-binding.{Format.ToString().ToLower()}", _serializer.Serialize( new V1ClusterRoleBinding { ApiVersion = $"{V1ClusterRoleBinding.KubeGroup}/{V1ClusterRoleBinding.KubeApiVersion}", Kind = V1ClusterRoleBinding.KubeKind, Metadata = new V1ObjectMeta { Name = "operator-role-binding" }, RoleRef = new V1RoleRef(V1ClusterRole.KubeGroup, V1ClusterRole.KubeKind, "operator-role"), Subjects = new List <V1Subject> { new(V1ServiceAccount.KubeKind, "default", namespaceProperty: "system"), }, },
public async Task <int> OnExecuteAsync(CommandLineApplication app) { var fileWriter = new FileWriter(app.Out); if (OutputPath != null && _hasWebhooks && (!File.Exists(Path.Join(OutputPath, "ca.pem")) || !File.Exists(Path.Join(OutputPath, "ca-key.pem")))) { using var certManager = new CertificateGenerator(app.Out); await certManager.CreateCaCertificateAsync(OutputPath); } fileWriter.Add( $"kustomization.{Format.ToString().ToLower()}", _serializer.Serialize( new KustomizationConfig { Resources = new List <string> { $"deployment.{Format.ToString().ToLower()}", }, CommonLabels = new Dictionary <string, string> { { "operator-element", "operator-instance" }, }, ConfigMapGenerator = _hasWebhooks ? new List <KustomizationConfigMapGenerator> { new() { Name = "webhook-ca", Files = new List <string> { "ca.pem", "ca-key.pem", }, }, new() { Name = "webhook-config", Literals = new List <string> { "KESTREL__ENDPOINTS__HTTP__URL=http://0.0.0.0:80", "KESTREL__ENDPOINTS__HTTPS__URL=https://0.0.0.0:443", "KESTREL__ENDPOINTS__HTTPS__CERTIFICATE__PATH=/certs/server.pem", "KESTREL__ENDPOINTS__HTTPS__CERTIFICATE__KEYPATH=/certs/server-key.pem", }, }, }