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

Add bootstrap command for gitops cli to bootstrap WGE #3371

Merged
merged 168 commits into from
Oct 12, 2023
Merged
Changes from 1 commit
Commits
Show all changes
168 commits
Select commit Hold shift + click to select a range
24c84b1
init gitops bootstrap command for wge
waleedhammam Aug 6, 2023
5790b43
add checks for entitlement and flux
waleedhammam Aug 7, 2023
06ee477
Merge branch 'main' into 3165-onboarding-cli-mvp
Samra10 Aug 8, 2023
7dd9d30
Add wge version choise list
Samra10 Aug 9, 2023
9b56a86
Merge branch 'main' into 3165-onboarding-cli-mvp
Samra10 Aug 9, 2023
a0f4806
add create admin username and password secret
waleedhammam Aug 9, 2023
1113f4e
add install wge
waleedhammam Aug 9, 2023
53e4f69
fix adding admin password
waleedhammam Aug 10, 2023
a11f30a
Merge branch 'main' into 3165-onboarding-cli-mvp
waleedhammam Aug 10, 2023
d35124d
fix linting
Samra10 Aug 10, 2023
970a1c7
Merge branch 'main' into 3165-onboarding-cli-mvp
Samra10 Aug 10, 2023
17282df
run go mod tidy
waleedhammam Aug 13, 2023
ab79c4e
enable ingress
waleedhammam Aug 13, 2023
8c978f6
add domain type selector
waleedhammam Aug 14, 2023
3d5d643
Merge branch 'main' into 3165-onboarding-cli-mvp
waleedhammam Aug 14, 2023
0b55a06
add option to bootstrap flux
waleedhammam Aug 14, 2023
f7f2f56
adjust bootstraping flux and domain
waleedhammam Aug 15, 2023
678dc19
add install extra controllers
waleedhammam Aug 15, 2023
a960f85
fix lint
waleedhammam Aug 15, 2023
b6edbb6
Merge branch 'main' into 3165-onboarding-cli-mvp
waleedhammam Aug 16, 2023
62b7af5
rename package checks to commands
waleedhammam Aug 21, 2023
6ed6f18
refactor packages
waleedhammam Aug 21, 2023
10c1b06
early exit
waleedhammam Aug 22, 2023
4c8b1f2
refactor errors and add utils for git repos
waleedhammam Aug 22, 2023
9767330
refactor wge installation to use files
waleedhammam Aug 22, 2023
62d97c3
refactor extra controllers
waleedhammam Aug 22, 2023
589d1b3
remove extra unneeded values
waleedhammam Aug 22, 2023
c34ea30
Add OIDC
Samra10 Aug 21, 2023
b41df39
update portforward
Samra10 Aug 22, 2023
719026d
add admin password revert
Samra10 Aug 22, 2023
724aa41
refactor error handeling
waleedhammam Aug 22, 2023
b3b1c02
Merge branch 'main' into 3165-onboarding-cli-mvp
waleedhammam Aug 22, 2023
ef6ba5c
fix unhandeled errors
waleedhammam Aug 22, 2023
a262d1a
refactor creating helmrepos and helmreleases
waleedhammam Aug 22, 2023
7e1e346
Merge branch 'main' into 3165-onboarding-cli-mvp
waleedhammam Aug 22, 2023
a1439f1
refactor styling
waleedhammam Aug 23, 2023
4ef75b1
go mod tidy
waleedhammam Aug 23, 2023
ce4fee0
split utils
waleedhammam Aug 23, 2023
3df5fa8
Add OIDC
Samra10 Aug 21, 2023
31fe6ba
refactor creating extra controllers
waleedhammam Aug 23, 2023
76962e1
move install extra controller to commands
waleedhammam Aug 23, 2023
94c21f9
add oidc
waleedhammam Aug 23, 2023
373d21b
Merge branch '3165-onboarding-cli-mvp' into onboarding-cli-oidc
Samra10 Aug 23, 2023
eaa71dc
Add OIDC
Samra10 Aug 21, 2023
fcae8c8
install capi controller
waleedhammam Aug 23, 2023
ee0fae3
add terraform controller
waleedhammam Aug 23, 2023
afcaeb0
Merge branch '3165-onboarding-cli-mvp' into onboarding-cli-oidc
Samra10 Aug 24, 2023
b99ed19
refactor OIDC cli
Samra10 Aug 24, 2023
02abb0a
fix linting
Samra10 Aug 24, 2023
548a25e
fix lintting
Samra10 Aug 24, 2023
493ae91
fix lint
Samra10 Aug 24, 2023
2479cd4
fix lint
Samra10 Aug 24, 2023
1cde545
Merge branch 'main' into 3165-onboarding-cli-mvp
waleedhammam Aug 24, 2023
395b12b
update OIDC CLI
Samra10 Aug 24, 2023
a8ef7e4
Merge branch '3165-onboarding-cli-mvp' into onboarding-cli-oidc
waleedhammam Aug 24, 2023
8e8bca1
handle error msgs
waleedhammam Aug 24, 2023
46e5d03
move check mark to method
waleedhammam Aug 24, 2023
cb113e6
reformat error
waleedhammam Aug 24, 2023
3521774
cleanup
waleedhammam Aug 24, 2023
60d0c46
update CLI OIDC
Samra10 Aug 24, 2023
f4dc771
fix confirm input
waleedhammam Aug 24, 2023
9f3fd20
type
waleedhammam Aug 24, 2023
fccdde9
Add localhost portforward info
Samra10 Aug 24, 2023
487036a
add gitopssets controller
waleedhammam Aug 28, 2023
acac4a9
enable pipelines controller and cluster-controller and gitopssets by …
waleedhammam Aug 28, 2023
733a27f
remove gitops sets
waleedhammam Aug 28, 2023
7e9a4a9
handle existing secrets
waleedhammam Aug 28, 2023
7982d24
Update onboarding CLI messages
Samra10 Aug 28, 2023
a351dce
cleanup utils
waleedhammam Aug 29, 2023
ddc90de
cleanup utils
waleedhammam Aug 29, 2023
4eeb147
cleanup domain
waleedhammam Aug 29, 2023
8bd31cc
cleanup utils
waleedhammam Aug 29, 2023
826bdc6
cleanup input
waleedhammam Aug 29, 2023
8246229
cleanup input
waleedhammam Aug 29, 2023
d1fdc54
edit messages and variableNames
Samra10 Aug 29, 2023
942bf6a
update cli messages
Samra10 Aug 29, 2023
61b26df
cleanup variables
waleedhammam Aug 29, 2023
2226c44
Merge pull request #3240 from weaveworks/onboarding-cli-oidc
waleedhammam Aug 29, 2023
f0ea1c2
Merge branch 'main' into 3165-onboarding-cli-mvp
waleedhammam Aug 29, 2023
e2c84e6
cleanup constants
waleedhammam Aug 29, 2023
e90003e
cleanup constants
waleedhammam Aug 29, 2023
9400930
Merge branch 'main' into 3165-onboarding-cli-mvp
waleedhammam Aug 30, 2023
cc8ace7
add unit test for k8s utils and refactor accordingly
waleedhammam Sep 10, 2023
8af84b8
add unit tests for flux
waleedhammam Sep 10, 2023
0de7470
add unit test for admin password
waleedhammam Sep 10, 2023
f8aa97b
Add unit -test for adding capi & policy-agent
Samra10 Sep 11, 2023
651766e
move controllers under gitops add
Samra10 Sep 11, 2023
183c648
Merge branch 'main' into 3165-onboarding-cli-mvp
Samra10 Sep 11, 2023
1c01c1b
add unit test for wge version
waleedhammam Sep 11, 2023
a8a285b
test oidc get issuer
waleedhammam Sep 11, 2023
85560c9
Move controllers under gitops add
Samra10 Sep 12, 2023
b381e87
Move controllers under gitops add
Samra10 Sep 13, 2023
46fa45d
Merge branch 'main' into 3165-onboarding-cli-mvp
Samra10 Sep 13, 2023
9f4f7c6
pause add controllers tests
Samra10 Sep 13, 2023
e896f55
restore install controller function after setup
waleedhammam Sep 14, 2023
612a334
Merge branch 'main' into 3165-onboarding-cli-mvp
waleedhammam Sep 18, 2023
175c57f
fix controllers
waleedhammam Sep 18, 2023
2e508f5
pass opts to controllers
waleedhammam Sep 18, 2023
a155d6f
refactor git utilits
Samra10 Sep 18, 2023
7e05b24
refactor git utilities
Samra10 Sep 18, 2023
a02d3c7
prepare bootstrap bommand for release1
waleedhammam Sep 19, 2023
79b32a9
address messages and languague
waleedhammam Sep 19, 2023
39af40a
clean extra variables
waleedhammam Sep 19, 2023
9c6d1a1
Merge branch 'main' into 3165-onboarding-cli
waleedhammam Sep 19, 2023
6dc433d
remove oidc flow to another branch
waleedhammam Sep 19, 2023
328f93f
Merge branch 'main' into 3165-onboarding-cli
waleedhammam Sep 19, 2023
560e3cf
Merge branch 'main' into 3165-onboarding-cli
waleedhammam Sep 19, 2023
1cfd53f
Update cmd/gitops/app/bootstrap/cmd.go
waleedhammam Sep 20, 2023
fb483ef
Update cmd/gitops/app/bootstrap/cmd.go
waleedhammam Sep 20, 2023
6bb8566
refactor git utility & add unit-test
Samra10 Sep 20, 2023
0de91a9
remove out of scope componenets
waleedhammam Sep 20, 2023
c434bcb
apply code review comments to refactor file names and error messages
waleedhammam Sep 20, 2023
e7b68ef
move bootstrap package under pkg
waleedhammam Sep 20, 2023
d26f07b
refactor using the k8s client and add silent mode
waleedhammam Sep 24, 2023
e7b2a10
fix admin password
waleedhammam Sep 24, 2023
f0fddac
verify username and password
waleedhammam Sep 24, 2023
9b01e8f
remove unused methods
waleedhammam Sep 24, 2023
a85fa41
Merge branch 'main' into 3165-onboarding-cli
waleedhammam Sep 24, 2023
ce478f4
fix spelling
waleedhammam Sep 25, 2023
25670c1
Merge branch 'main' into 3165-onboarding-cli
waleedhammam Sep 25, 2023
26d0587
remove aws related stuff
waleedhammam Sep 25, 2023
fb3e301
use git library
waleedhammam Sep 25, 2023
a20f836
fix lint
waleedhammam Sep 26, 2023
67da432
Merge branch 'main' into 3165-onboarding-cli
waleedhammam Sep 26, 2023
54e03ff
imporve error messages to stage failures
waleedhammam Sep 27, 2023
33ce42f
Merge branch 'main' into 3165-onboarding-cli
waleedhammam Oct 2, 2023
59e390c
adjust gitopssets values and installation checks
waleedhammam Oct 2, 2023
7e7fe61
clean silent mode
waleedhammam Oct 2, 2023
810cdd6
add checks for kubeconfig
waleedhammam Oct 2, 2023
477c381
adjust admin password
waleedhammam Oct 2, 2023
f7a91f7
Merge branch 'main' into 3165-onboarding-cli
waleedhammam Oct 2, 2023
f9af6d8
refactor commands to use config interface struct
waleedhammam Oct 2, 2023
68b9ae4
improve error messages
waleedhammam Oct 2, 2023
14a2538
Merge branch 'main' into 3165-onboarding-cli
waleedhammam Oct 2, 2023
dd7ae8f
remove unused variable
waleedhammam Oct 2, 2023
a5201ae
wip adding cli design doc
enekofb Oct 3, 2023
ced1950
wip adding cli design doc
enekofb Oct 3, 2023
949bda3
add error guidance
enekofb Oct 3, 2023
81d75ab
rename config to bootstrapper to be more clear
waleedhammam Oct 3, 2023
2521218
Merge branch 'main' into 3165-onboarding-cli
waleedhammam Oct 3, 2023
e38445a
refactor commands to use steps pattern
waleedhammam Oct 4, 2023
970c2b5
continue on refactor commands to use steps pattern
waleedhammam Oct 5, 2023
988dade
Merge branch 'main' into 3165-onboarding-cli
waleedhammam Oct 5, 2023
3dd6d8c
fix ssh authenticate by explictly asking for private key file
waleedhammam Oct 9, 2023
5aa5270
Merge branch 'main' into 3165-onboarding-cli
waleedhammam Oct 9, 2023
b94e36f
added integration test, refactored configuration and design (#3458)
enekofb Oct 10, 2023
6cec7ed
add events and error messages and fix domain bug
waleedhammam Oct 10, 2023
75432c9
add current context
waleedhammam Oct 10, 2023
3df36a5
fix lint
waleedhammam Oct 10, 2023
9cd2d3b
add entitlement expiration message
waleedhammam Oct 10, 2023
cc80cb0
fix entitlement expiration
waleedhammam Oct 10, 2023
c162789
fix entitlement expiration
waleedhammam Oct 10, 2023
6b1c1db
seperate entitlement secret validations
waleedhammam Oct 10, 2023
3c05048
add messages for flux
waleedhammam Oct 10, 2023
e4a2c2e
edit messages to small letter and update success messages
waleedhammam Oct 11, 2023
c598ddb
add validation for password and wge version
waleedhammam Oct 11, 2023
3f2b781
add test cases for admin password create creds
waleedhammam Oct 11, 2023
b3e184a
add test cases for domain type
waleedhammam Oct 11, 2023
c9dbfee
update entitlement test
waleedhammam Oct 11, 2023
2981ee4
add validation on password input
waleedhammam Oct 12, 2023
d883893
remove aws related message
waleedhammam Oct 12, 2023
4824da5
panic in case of casting error to give more context about the error
waleedhammam Oct 12, 2023
d5e72f7
handle portforward and error messages
waleedhammam Oct 12, 2023
10f1af0
Merge branch 'main' into 3165-onboarding-cli
waleedhammam Oct 12, 2023
c00dd68
fix external dns spacing
waleedhammam Oct 12, 2023
25de99c
add validation on domain type
waleedhammam Oct 12, 2023
391f660
Cli eneko review (#3474)
enekofb Oct 12, 2023
1d88da0
Merge branch 'main' into 3165-onboarding-cli
waleedhammam Oct 12, 2023
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
Prev Previous commit
Next Next commit
Add wge version choise list
Samra10 committed Aug 9, 2023
commit 7dd9d308b106a4b13588425754b3c578e5c7710b
44 changes: 44 additions & 0 deletions cmd/gitops/app/bootstrap/checks/common.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
package checks

import (
"context"
"encoding/base64"
"errors"
"fmt"
"os"
"path/filepath"

"github.com/manifoldco/promptui"
"golang.org/x/exp/slices"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
)

type promptContent struct {
@@ -72,3 +79,40 @@ func promptGetSelect(pc promptContent, items []string) string {

return result
}

// retunn the whole secret
func getSecret(secretNamespace, secretName string) (*corev1.Secret, error) {
// Path to the kubeconfig file. This is typically located at "~/.kube/config".
// Obtain the user's home directory.
home, err := os.UserHomeDir()
if err != nil {
panic(err.Error())
}

// Construct the full path to the kubeconfig file.
kubeconfig := filepath.Join(home, ".kube", "config")

config, err := clientcmd.BuildConfigFromFlags("", kubeconfig)
if err != nil {
panic(err.Error())
}

// Create a new Kubernetes client using the config.
clientset, err := kubernetes.NewForConfig(config)
if err != nil {
panic(err.Error())
}

// Fetch the secret from the Kubernetes cluster.
secret, err := clientset.CoreV1().Secrets(secretNamespace).Get(context.TODO(), secretName, v1.GetOptions{})
if err != nil {
return nil, err
}

return secret, nil
}

func isValidBase64(s string) bool {
_, err := base64.StdEncoding.DecodeString(s)
return err == nil
}
21 changes: 2 additions & 19 deletions cmd/gitops/app/bootstrap/checks/entitlement.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
package checks

import (
"context"
"fmt"
"os"
"path/filepath"

"golang.org/x/exp/slices"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/util/homedir"
)

const ENTITLEMENT_SECRET_NAME string = "weave-gitops-enterprise-credentials"
@@ -28,19 +22,8 @@ func CheckEntitlementFile() {
os.Exit(1)
}

path := filepath.Join(homedir.HomeDir(), ".kube", "config")
// use the current context in kubeconfig
config, err := clientcmd.BuildConfigFromFlags("", path)
if err != nil {
panic(err.Error())
}
// create the clientset
clientset, err := kubernetes.NewForConfig(config)
if err != nil {
panic(err.Error())
}

secret, err := clientset.CoreV1().Secrets(ENTITLEMENT_SECRET_NAMESPACE).Get(context.TODO(), ENTITLEMENT_SECRET_NAME, v1.GetOptions{})
//get secret from getSecret()
secret, err := getSecret(ENTITLEMENT_SECRET_NAMESPACE, ENTITLEMENT_SECRET_NAME)
if err != nil || secret.Data["entitlement"] == nil {
fmt.Println("invalid entitlement file!")
os.Exit(1)
103 changes: 102 additions & 1 deletion cmd/gitops/app/bootstrap/checks/wge-version.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,48 @@
package checks

import (
"encoding/base64"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"

"gopkg.in/yaml.v2"
corev1 "k8s.io/api/core/v1"
)

const CHART_URL string = "https://charts.dev.wkp.weave.works/releases/charts-v3/index.yaml"

type HelmChart struct {
ApiVersion string
Entries map[string][]ChartEntry
Generated string
}

type ChartEntry struct {
ApiVersion string
Name string
Version string
}

func CheckWgeVersion() {
VERSIONS := []string{"v0.29.1", "v0.29.0", "v0.28.0"}
//get secret from getSecret()
entitlementSecret, err := getSecret(ENTITLEMENT_SECRET_NAMESPACE, ENTITLEMENT_SECRET_NAME)
if err != nil {
fmt.Printf("An error occured %v\n", err)
os.Exit(1)
}

//get username and password from entitlementSecret
username, password, err := getSecretUsernamePassword(entitlementSecret)
if err != nil {
fmt.Printf("An error occured %v\n", err)
os.Exit(1)
}

VERSIONS := fetchHelmChart(username, password)

versionSelectorPrompt := promptContent{
"",
"Please select a version for WGE to be installed",
@@ -14,3 +51,67 @@ func CheckWgeVersion() {

fmt.Printf("Installing Weave Gitops Enterprise ... %s\n", selectedVersion)
}

func fetchHelmChart(username, password string) []string {
client := &http.Client{}
req, err := http.NewRequest("GET", CHART_URL, nil)
if err != nil {
log.Fatalf("error creating request: %v", err)
}

req.SetBasicAuth(username, password)

resp, err := client.Do(req)
if err != nil {
log.Fatalf("error performing request: %v", err)
}
defer resp.Body.Close()

bodyBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatalf("error reading response: %v", err)
}

var chart HelmChart
err = yaml.Unmarshal(bodyBytes, &chart)
if err != nil {
log.Fatalf("error parsing yaml: %v", err)
}

entries := chart.Entries["mccp"]
var versions []string
for _, entry := range entries {
if entry.Name == "mccp" {
versions = append(versions, entry.Version)
if len(versions) == 3 {
break
}
}
}
return versions
}

func getSecretUsernamePassword(secret *corev1.Secret) (string, string, error) {

username := string(secret.Data["username"])
password := string(secret.Data["password"])

// If the username and password are base64 encoded, decode them.
if isValidBase64(username) {
decodedUsername, err := base64.StdEncoding.DecodeString(username)
if err != nil {
return "", "", err
}
username = string(decodedUsername)
}

if isValidBase64(password) {
decodedPassword, err := base64.StdEncoding.DecodeString(password)
if err != nil {
return "", "", err
}
password = string(decodedPassword)
}

return username, password, nil
}