Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] Add Helm Install Handler #4903

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading