public async Task <int> OnExecuteAsync(CommandLineApplication app) { var role = _serializer.Serialize(GenerateManagerRbac(), Format); var roleBinding = _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 V1Subject(V1ServiceAccount.KubeKind, "default", namespaceProperty: "system") } }, Format); if (!string.IsNullOrWhiteSpace(OutputPath)) { Directory.CreateDirectory(OutputPath); await using var roleFile = File.Open(Path.Join(OutputPath, $"operator-role.{Format.ToString().ToLower()}"), FileMode.Create); await roleFile.WriteAsync(Encoding.UTF8.GetBytes(role)); await using var bindingFile = File.Open(Path.Join(OutputPath, $"operator-role-binding.{Format.ToString().ToLower()}"), FileMode.Create); await bindingFile.WriteAsync(Encoding.UTF8.GetBytes(roleBinding)); var kustomize = new KustomizationConfig { Resources = new List <string> { $"operator-role.{Format.ToString().ToLower()}", $"operator-role-binding.{Format.ToString().ToLower()}", }, CommonLabels = new Dictionary <string, string> { { "operator-element", "rbac" }, }, }; var kustomizeOutput = Encoding.UTF8.GetBytes(_serializer.Serialize(kustomize, Format)); await using var kustomizationFile = File.Open(Path.Join(OutputPath, $"kustomization.{Format.ToString().ToLower()}"), FileMode.Create); await kustomizationFile.WriteAsync(kustomizeOutput); } else { await app.Out.WriteLineAsync(role); await app.Out.WriteLineAsync(roleBinding); } return(ExitCodes.Success); }
public async Task <int> OnExecuteAsync(CommandLineApplication app) { var output = _serializer.Serialize(new V1Deployment( $"{V1Deployment.KubeGroup}/{V1Deployment.KubeApiVersion}", V1Deployment.KubeKind, new V1ObjectMeta(name: "operator"), new V1DeploymentSpec { Replicas = 1, RevisionHistoryLimit = 0, Template = new V1PodTemplateSpec { Spec = new V1PodSpec { TerminationGracePeriodSeconds = 10, Containers = new List <V1Container> { new V1Container { Image = "operator", Name = "operator", Resources = new V1ResourceRequirements { Requests = new Dictionary <string, ResourceQuantity> { { "cpu", new ResourceQuantity("100m") }, { "memory", new ResourceQuantity("64Mi") }, }, Limits = new Dictionary <string, ResourceQuantity> { { "cpu", new ResourceQuantity("100m") }, { "memory", new ResourceQuantity("128Mi") }, }, }, }, }, }, }, }), Format); if (!string.IsNullOrWhiteSpace(OutputPath)) { Directory.CreateDirectory(OutputPath); await using var file = File.Open(Path.Join(OutputPath, $"deployment.{Format.ToString().ToLower()}"), FileMode.Create); await file.WriteAsync(Encoding.UTF8.GetBytes(output)); var kustomize = new KustomizationConfig { Resources = new List <string> { $"deployment.{Format.ToString().ToLower()}" }, CommonLabels = new Dictionary <string, string> { { "operator-element", "operator-instance" }, }, }; var kustomizeOutput = Encoding.UTF8.GetBytes(_serializer.Serialize(kustomize, Format)); await using var kustomizationFile = File.Open(Path.Join(OutputPath, $"kustomization.{Format.ToString().ToLower()}"), FileMode.Create); await kustomizationFile.WriteAsync(kustomizeOutput); } else { await app.Out.WriteLineAsync(output); } return(ExitCodes.Success); }
public async Task <int> OnExecuteAsync(CommandLineApplication app) { var output = _serializer.Serialize( new V1Deployment( $"{V1Deployment.KubeGroup}/{V1Deployment.KubeApiVersion}", V1Deployment.KubeKind, new V1ObjectMeta(name: "operator"), new V1DeploymentSpec { Replicas = 1, RevisionHistoryLimit = 0, Template = new V1PodTemplateSpec { Spec = new V1PodSpec { TerminationGracePeriodSeconds = 10, Containers = new List <V1Container> { new V1Container { Image = "operator", Name = "operator", Env = new List <V1EnvVar> { new V1EnvVar { Name = "POD_NAMESPACE", ValueFrom = new V1EnvVarSource { FieldRef = new V1ObjectFieldSelector { FieldPath = "metadata.namespace", }, }, }, }, Ports = new List <V1ContainerPort> { new V1ContainerPort(80, name: "http"), }, LivenessProbe = new V1Probe( timeoutSeconds: 1, initialDelaySeconds: 30, httpGet: new V1HTTPGetAction("http", path: "/health")), ReadinessProbe = new V1Probe( timeoutSeconds: 1, initialDelaySeconds: 15, httpGet: new V1HTTPGetAction("http", path: "/ready")), Resources = new V1ResourceRequirements { Requests = new Dictionary <string, ResourceQuantity> { { "cpu", new ResourceQuantity("100m") }, { "memory", new ResourceQuantity("64Mi") }, }, Limits = new Dictionary <string, ResourceQuantity> { { "cpu", new ResourceQuantity("100m") }, { "memory", new ResourceQuantity("128Mi") }, }, }, }, }, }, }, }), Format); if (!string.IsNullOrWhiteSpace(OutputPath)) { Directory.CreateDirectory(OutputPath); await using var file = File.Open( Path.Join( OutputPath, $"deployment.{Format.ToString().ToLower()}"), FileMode.Create); await file.WriteAsync(Encoding.UTF8.GetBytes(output)); var kustomize = new KustomizationConfig { Resources = new List <string> { $"deployment.{Format.ToString().ToLower()}" }, CommonLabels = new Dictionary <string, string> { { "operator-element", "operator-instance" }, }, }; var kustomizeOutput = Encoding.UTF8.GetBytes(_serializer.Serialize(kustomize, Format)); await using var kustomizationFile = File.Open(Path.Join(OutputPath, $"kustomization.{Format.ToString().ToLower()}"), FileMode.Create); await kustomizationFile.WriteAsync(kustomizeOutput); } else { await app.Out.WriteLineAsync(output); } return(ExitCodes.Success); }