Skip to content

Commit

Permalink
minor fixes in challHandling funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
rizul2108 committed Dec 23, 2023
1 parent 2e1b1cb commit 7549335
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 25 deletions.
9 changes: 7 additions & 2 deletions cliHelpers/chalDeployerService/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"
"os"
"strconv"
"strings"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

Expand Down Expand Up @@ -75,7 +76,11 @@ func DeployChallenge() error {
teamName := "katana-team-" + strconv.Itoa(i)
err = deployment.DeployChallengeToCluster(folderName, teamName, patch, replicas)
if err != nil {
return err
if !(strings.Contains(err.Error(), "already exists")) {
return err
}else{
log.Println("Deployment already existed.")
}
}
url, err := challengedeployerservice.CreateServiceForChallenge(folderName, teamName, 3000, i)
if err != nil {
Expand Down Expand Up @@ -173,7 +178,7 @@ func DeleteChallenge(challengeName string) error {

//Delete service
log.Println("Deleting services associated with this challenge...")
err = serviceClient.Delete(context.TODO(), challengeName, metav1.DeleteOptions{})
err = serviceClient.Delete(context.TODO(), challengeName+"-svc-"+strconv.Itoa(i), metav1.DeleteOptions{})
if err != nil {
log.Println("Error in deleting service for "+challengeName+" in namespace "+teamNamespace, err)
continue
Expand Down
8 changes: 6 additions & 2 deletions lib/deployment/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,12 @@ func DeployChallengeToCluster(challengeName, teamName string, firstPatch bool, r
log.Println("Creating deployment...")
result, err := deploymentsClient.Create(context.TODO(), manifest, metav1.CreateOptions{})
if err != nil {
log.Println("Unable to create deployement")
panic(err)
if(!strings.Contains(err.Error(), "already exists")){
log.Println("Unable to create deployement")
panic(err)
}else{
log.Println("Deployment already existed")
}
}

log.Printf("Created deployment %q.\n", result.GetObjectMeta().GetName()+" in namespace "+teamNamespace)
Expand Down
23 changes: 4 additions & 19 deletions lib/utils/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,8 @@ func GetMongoIP() (string, error) {
}

func CopyFromPod(podName string, containerName string, pathInPod string, localFilePath string, ns ...string) error {
config, err := GetKubeConfig()
if err != nil {
return err
}

client, err := GetKubeClient()
if err != nil {
return err
}
config:=g.GlobalKubeConfig
client:=g.GlobalKubeClient

namespace := "katana"
if len(ns) > 0 {
Expand Down Expand Up @@ -183,16 +176,8 @@ func CopyFromPod(podName string, containerName string, pathInPod string, localFi
}

func CopyIntoPod(podName string, containerName string, pathInPod string, localFilePath string, ns ...string) error {
config, err := GetKubeConfig()
if err != nil {
return err
}

client, err := GetKubeClient()
if err != nil {
return err
}

config:=g.GlobalKubeConfig
client:=g.GlobalKubeClient
localFile, err := os.Open(localFilePath)
if err != nil {
log.Printf("Error opening local file: %s\n", err)
Expand Down
4 changes: 2 additions & 2 deletions services/challengedeployerservice/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ func Deploy(c *fiber.Ctx) error {
if err != nil {
return err
}
err = CopyChallengeIntoTsuka(challengePath, folderName, challengeType)
err = CopyFlagDataIntoKashira(challengePath, folderName)
if err != nil {
return err
}
err = CopyChallengeIntoTsuka(challengePath, folderName, challengeType)
err = CopyChallengeCheckerIntoKissaki(challengePath, folderName)
if err != nil {
return err
}
Expand Down

0 comments on commit 7549335

Please sign in to comment.