Skip to content

Commit

Permalink
feat: add helm handler
Browse files Browse the repository at this point in the history
Signed-off-by: dusdjhyeon <[email protected]>
  • Loading branch information
dusdjhyeon committed Sep 24, 2024
1 parent 58e59cc commit bf61e45
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 9 deletions.
4 changes: 4 additions & 0 deletions chaoscenter/graphql/server/graph/model/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions chaoscenter/graphql/server/pkg/chaos_infrastructure/infra_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,36 @@ func GetEndpoint(host string) (string, error) {
return host + "/api/query", nil
}

func GetHelmCommand(infra dbChaosInfra.ChaosInfra, infraURL string) string {
var (
infraNamespace string
DefaultInfraNamespace = "litmus"
)
if infra.InfraNamespace != nil && *infra.InfraNamespace != "" {
infraNamespace = *infra.InfraNamespace
} else {
infraNamespace = DefaultInfraNamespace
}
commands := fmt.Sprintf(`helm install litmus-agent litmuschaos/litmus-agent \
--namespace %s --create-namespace \
--set "LITMUS_URL=%s" \
--set "INFRA_ID=%s" \
--set "ACCESS_KEY=%s" \
--set "global.INFRA_MODE=%s"`,
infraNamespace,
infraURL,
infra.InfraID,
infra.AccessKey,
infra.InfraScope,
)
if infra.InfraScope == NamespaceScope {
commands += ` \
--set "crds.create=false" \
--set "workflow-controller.crds.create=false"`
}
return commands
}

func GetK8sInfraYaml(host string, infra dbChaosInfra.ChaosInfra) ([]byte, error) {

var config SubscriberConfigurations
Expand Down
42 changes: 33 additions & 9 deletions chaoscenter/graphql/server/pkg/chaos_infrastructure/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ const (
NamespaceScope string = "namespace"
)

type InstallationMode string

const (
Manifest InstallationMode = "kubernetes"
Helm InstallationMode = "helm"
)

type Service interface {
RegisterInfra(c context.Context, projectID string, input model.RegisterInfraRequest) (*model.RegisterInfraResponse, error)
ConfirmInfraRegistration(request model.InfraIdentity, r store.StateData) (*model.ConfirmInfraRegistrationResponse, error)
Expand Down Expand Up @@ -205,17 +212,34 @@ func (in *infraService) RegisterInfra(c context.Context, projectID string, input
return nil, err
}

manifestYaml, err := GetK8sInfraYaml(fmt.Sprintf("%s://%s", referrerURL.Scheme, referrerURL.Host), newInfra)
if err != nil {
return nil, err
if input.InstallationType == nil {
return nil, fmt.Errorf("installation type is required")
}

return &model.RegisterInfraResponse{
InfraID: newInfra.InfraID,
Token: token,
Name: newInfra.Name,
Manifest: string(manifestYaml),
}, nil
switch *input.InstallationType {
case string(Manifest):
manifestYaml, err := GetK8sInfraYaml(fmt.Sprintf("%s://%s", referrerURL.Scheme, referrerURL.Host), newInfra)
if err != nil {
return nil, err
}

return &model.RegisterInfraResponse{
InfraID: newInfra.InfraID,
Token: token,
Name: newInfra.Name,
Manifest: string(manifestYaml),
}, nil
case string(Helm):
helmCommand := GetHelmCommand(newInfra, fmt.Sprintf("%s://%s", referrerURL.Scheme, referrerURL.Host))
return &model.RegisterInfraResponse{
InfraID: newInfra.InfraID,
Token: token,
Name: newInfra.Name,
HelmCommand: helmCommand,
}, nil
default:
return nil, errors.New("invalid installation type")
}
}

// DeleteInfra takes infraIDs and r parameters, deletes the infras from the database and sends a request to the subscriber for clean-up
Expand Down

0 comments on commit bf61e45

Please sign in to comment.