This commit is contained in:
Kar
2026-02-01 20:38:58 +05:30
parent 52265ed4cc
commit 5e563fb436
11 changed files with 159 additions and 51 deletions

View File

@@ -4,6 +4,7 @@ import (
"bufio"
"context"
"fmt"
"os"
"os/exec"
"strings"
@@ -12,14 +13,24 @@ import (
)
type KubectlClient struct {
namespace string
namespace string
kubeconfig string
}
func NewKubectlClient(namespace string) *KubectlClient {
func NewKubectlClient(namespace, kubeconfig string) *KubectlClient {
if namespace == "" {
namespace = "default"
}
return &KubectlClient{namespace: namespace}
if kubeconfig == "" {
kubeconfig = os.Getenv("KUBECONFIG")
if kubeconfig == "" {
kubeconfig = ".env/cluster1.yaml"
}
}
return &KubectlClient{
namespace: namespace,
kubeconfig: kubeconfig,
}
}
func (k *KubectlClient) ApplyManifest(ctx context.Context, eventChan chan<- *events.Event, repoID int64, manifest string) error {
@@ -27,6 +38,7 @@ func (k *KubectlClient) ApplyManifest(ctx context.Context, eventChan chan<- *eve
args := []string{
"apply",
"-f", "-",
"--kubeconfig", k.kubeconfig,
"--namespace", k.namespace,
}
@@ -50,9 +62,9 @@ func (k *KubectlClient) ApplyManifest(ctx context.Context, eventChan chan<- *eve
func (k *KubectlClient) DeleteResources(ctx context.Context, eventChan chan<- *events.Event, repoID int64, appName string) error {
commands := [][]string{
{"delete", "deployment", appName, "--namespace", k.namespace},
{"delete", "service", appName, "--namespace", k.namespace},
{"delete", "configmap", appName, "--namespace", k.namespace},
{"delete", "deployment", appName, "--kubeconfig", k.kubeconfig, "--namespace", k.namespace},
{"delete", "service", appName, "--kubeconfig", k.kubeconfig, "--namespace", k.namespace},
{"delete", "configmap", appName, "--kubeconfig", k.kubeconfig, "--namespace", k.namespace},
}
for _, args := range commands {
@@ -74,6 +86,7 @@ func (k *KubectlClient) ScaleDeployment(ctx context.Context, eventChan chan<- *e
"scale",
"deployment", appName,
"--replicas", fmt.Sprintf("%d", replicas),
"--kubeconfig", k.kubeconfig,
"--namespace", k.namespace,
}
@@ -84,6 +97,7 @@ func (k *KubectlClient) GetDeploymentStatus(ctx context.Context, appName string)
cmd := "kubectl"
args := []string{
"get", "deployment", appName,
"--kubeconfig", k.kubeconfig,
"--namespace", k.namespace,
"-o", "jsonpath='{.status.readyReplicas}'",
}

View File

@@ -111,7 +111,7 @@ spec:
func getAppPort(repoType model.RepoType) int {
switch repoType {
case model.TypeNodeJS:
return 3000
return 80 // React apps serve on port 80 with nginx
case model.TypePython:
return 8000
default: