Skip to content
This repository was archived by the owner on Nov 22, 2022. It is now read-only.
This repository was archived by the owner on Nov 22, 2022. It is now read-only.

Configuring a Kubernetes cluster with glab #716

@sunny0826

Description

@sunny0826

Describe the feature or problem you'd like to solve

Hopefully, we can use glab to configure a Kubernetes cluster for a gitlab project.

Propose a Solution

we can use go-gitlab to implement this feature, and in fact, I have done so in my own project.

import (
	"fmt"
	"github.com/xanzy/go-gitlab"
)

type GitlabCluster struct {
	ApiUrl      string
	Token       string
	CaCert      string
	Namespace   string
	GitlabToken string
	GitlabUrl   string
}

func (gc *GitlabCluster) ConfigGitlab(name, envScope, git string) error {
	client, err := NewGitlabClient(gc.GitlabToken, gc.GitlabUrl)
	if err != nil {
		return err
	}
	addOpt := &gitlab.AddClusterOptions{
		Name: gitlab.String(name),
		PlatformKubernetes: &gitlab.AddPlatformKubernetesOptions{
			APIURL:    gitlab.String(gc.ApiUrl),
			Token:     gitlab.String(gc.Token),
			CaCert:    gitlab.String(gc.CaCert),
			Namespace: gitlab.String(gc.Namespace),
		},
		EnvironmentScope: gitlab.String(envScope),
		Managed:          gitlab.Bool(false),
	}
	_, _, err = client.ProjectCluster.AddCluster(git, addOpt)
	if err != nil {
		return err
	}
	return nil
}

Additional context

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions