Skip to content

Commit

Permalink
Merge pull request #29 from replicatedhq/fix-deployment
Browse files Browse the repository at this point in the history
Multiple deployment options
  • Loading branch information
marccampbell authored Aug 30, 2019
2 parents c4dbf3a + 99f2b20 commit 0932e32
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 32 deletions.
9 changes: 1 addition & 8 deletions pkg/kotsadm/kotsadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client/config"
)

const (
kotsadmURL = "https://gist.githubusercontent.com/marccampbell/fb4b367d66beeddb5b4258a82704f75f/raw/e44b48579f34375e8608fd0d0bee350dfb76e7af/kotsadm.yaml"
)

var (
postgresPassword = uuid.New().String()
minioAccessKey = uuid.New().String()
minioSecret = uuid.New().String()
autoCreateClusterToken = uuid.New().String()
)

Expand Down Expand Up @@ -69,7 +62,7 @@ func YAML(deployOptions DeployOptions) (map[string][]byte, error) {
docs[n] = v
}

migrationDocs, err := getMigrationsYAML(deployOptions.Namespace)
migrationDocs, err := getMigrationsYAML(deployOptions)
if err != nil {
return nil, errors.Wrap(err, "failed to get migrations yaml")
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/kotsadm/schemahero.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import (
"k8s.io/client-go/kubernetes/scheme"
)

func getMigrationsYAML(namespace string) (map[string][]byte, error) {
func getMigrationsYAML(deployOptions DeployOptions) (map[string][]byte, error) {
docs := map[string][]byte{}
s := json.NewYAMLSerializer(json.DefaultMetaFactory, scheme.Scheme, scheme.Scheme)

var pod bytes.Buffer
if err := s.Encode(migrationsPod(namespace), &pod); err != nil {
if err := s.Encode(migrationsPod(deployOptions), &pod); err != nil {
return nil, errors.Wrap(err, "failed to marshal migrations pod")
}
docs["migrations.yaml"] = pod.Bytes()
Expand Down Expand Up @@ -71,7 +71,7 @@ func waitForHealthyPostgres(namespace string, clientset *kubernetes.Clientset) (
}

func createSchemaHeroPod(deployOptions DeployOptions, clientset *kubernetes.Clientset) error {
_, err := clientset.CoreV1().Pods(deployOptions.Namespace).Create(migrationsPod(deployOptions.Namespace))
_, err := clientset.CoreV1().Pods(deployOptions.Namespace).Create(migrationsPod(deployOptions))
if err != nil {
return errors.Wrap(err, "failed to create pod")
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/kotsadm/schemahero_objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func migrationsPod(namespace string) *corev1.Pod {
func migrationsPod(deployOptions DeployOptions) *corev1.Pod {
name := fmt.Sprintf("kotsadm-migrations-%d", time.Now().Unix())

pod := &corev1.Pod{
Expand All @@ -18,7 +18,7 @@ func migrationsPod(namespace string) *corev1.Pod {
},
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
Namespace: deployOptions.Namespace,
},
Spec: corev1.PodSpec{
RestartPolicy: corev1.RestartPolicyOnFailure,
Expand All @@ -38,7 +38,7 @@ func migrationsPod(namespace string) *corev1.Pod {
},
{
Name: "SCHEMAHERO_URI",
Value: fmt.Sprintf("postgresql://kotsadm:%s@kotsadm-postgres/kotsadm?connect_timeout=10&sslmode=disable", postgresPassword),
Value: fmt.Sprintf("postgresql://kotsadm:%s@kotsadm-postgres/kotsadm?connect_timeout=10&sslmode=disable", deployOptions.PostgresPassword),
},
},
},
Expand Down
10 changes: 5 additions & 5 deletions pkg/kotsadm/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func getSecretsYAML(deployOptions *DeployOptions) (map[string][]byte, error) {
docs["secret-jwt.yaml"] = jwt.Bytes()

var pg bytes.Buffer
if err := s.Encode(pgSecret(deployOptions.Namespace, postgresPassword), &pg); err != nil {
if err := s.Encode(pgSecret(deployOptions.Namespace, deployOptions.PostgresPassword), &pg); err != nil {
return nil, errors.Wrap(err, "failed to marshal pg secret")
}
docs["secret-pg.yaml"] = pg.Bytes()
Expand Down Expand Up @@ -64,7 +64,7 @@ func ensureSecrets(deployOptions *DeployOptions, clientset *kubernetes.Clientset
return errors.Wrap(err, "failed to ensure jwt session secret")
}

if err := ensurePostgresSecret(deployOptions.Namespace, clientset); err != nil {
if err := ensurePostgresSecret(*deployOptions, clientset); err != nil {
return errors.Wrap(err, "failed to ensure postgres secret")
}

Expand Down Expand Up @@ -111,14 +111,14 @@ func ensureJWTSessionSecret(namespace string, clientset *kubernetes.Clientset) e
return nil
}

func ensurePostgresSecret(namespace string, clientset *kubernetes.Clientset) error {
_, err := clientset.CoreV1().Secrets(namespace).Get("kotsadm-postgres", metav1.GetOptions{})
func ensurePostgresSecret(deployOptions DeployOptions, clientset *kubernetes.Clientset) error {
_, err := clientset.CoreV1().Secrets(deployOptions.Namespace).Get("kotsadm-postgres", metav1.GetOptions{})
if err != nil {
if !kuberneteserrors.IsNotFound(err) {
return errors.Wrap(err, "failed to get existing postgres secret")
}

_, err := clientset.CoreV1().Secrets(namespace).Create(pgSecret(namespace, postgresPassword))
_, err := clientset.CoreV1().Secrets(deployOptions.Namespace).Create(pgSecret(deployOptions.Namespace, deployOptions.PostgresPassword))
if err != nil {
return errors.Wrap(err, "failed to create postgres secret")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/pull/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ func Pull(upstreamURI string, pullOptions PullOptions) (string, error) {
fetchOptions := upstream.FetchOptions{}
fetchOptions.HelmRepoURI = pullOptions.HelmRepoURI
fetchOptions.LocalPath = pullOptions.LocalPath
fetchOptions.SharedPassword = pullOptions.SharedPassword

if pullOptions.LicenseFile != "" {
license, err := parseLicenseFromFile(pullOptions.LicenseFile)
Expand All @@ -102,6 +101,7 @@ func Pull(upstreamURI string, pullOptions PullOptions) (string, error) {
RootDir: pullOptions.RootDir,
CreateAppDir: true,
IncludeAdminConsole: uri.Scheme == "replicated" && !pullOptions.ExcludeAdminConsole,
SharedPassword: pullOptions.SharedPassword,
}
if err := u.WriteUpstream(writeUpstreamOptions); err != nil {
log.FinishSpinnerWithError()
Expand Down
7 changes: 3 additions & 4 deletions pkg/upstream/admin-console.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package upstream

import (
"fmt"
"io/ioutil"
"os"
"path"
Expand All @@ -14,9 +13,9 @@ import (
"k8s.io/client-go/kubernetes/scheme"
)

func generateAdminConsoleFiles(renderDir string) ([]UpstreamFile, error) {
func generateAdminConsoleFiles(renderDir string, sharedPassword string) ([]UpstreamFile, error) {
if _, err := os.Stat(path.Join(renderDir, "admin-console")); os.IsNotExist(err) {
return generateNewAdminConsoleFiles("", "", "", "", "", "")
return generateNewAdminConsoleFiles(sharedPassword, "", "", "", "", "")
}

existingFiles, err := ioutil.ReadDir(path.Join(renderDir, "admin-console"))
Expand Down Expand Up @@ -102,7 +101,6 @@ func findFileAndReadSecret(secretName string, key string, renderDir string, file
func generateNewAdminConsoleFiles(sharedPassword string, sharedPasswordBcrypt string, s3AccessKey string, s3SecretKey string, jwt string, pgPassword string) ([]UpstreamFile, error) {
upstreamFiles := []UpstreamFile{}

fmt.Printf("pg pass = %s\n", pgPassword)
deployOptions := kotsadm.DeployOptions{
Namespace: "default",
SharedPassword: sharedPassword,
Expand All @@ -111,6 +109,7 @@ func generateNewAdminConsoleFiles(sharedPassword string, sharedPasswordBcrypt st
S3SecretKey: s3SecretKey,
JWT: jwt,
PostgresPassword: pgPassword,
Hostname: "localhost:8800",
}

if deployOptions.SharedPasswordBcrypt == "" && deployOptions.SharedPassword == "" {
Expand Down
11 changes: 5 additions & 6 deletions pkg/upstream/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ import (
)

type FetchOptions struct {
HelmRepoName string
HelmRepoURI string
LocalPath string
License *kotsv1beta1.License
SharedPassword string
HelmRepoName string
HelmRepoURI string
LocalPath string
License *kotsv1beta1.License
}

func FetchUpstream(upstreamURI string, fetchOptions *FetchOptions) (*Upstream, error) {
Expand All @@ -38,7 +37,7 @@ func downloadUpstream(upstreamURI string, fetchOptions *FetchOptions) (*Upstream
return downloadHelm(u, fetchOptions.HelmRepoURI)
}
if u.Scheme == "replicated" {
return downloadReplicated(u, fetchOptions.LocalPath, fetchOptions.License, fetchOptions.SharedPassword)
return downloadReplicated(u, fetchOptions.LocalPath, fetchOptions.License)
}
if u.Scheme == "git" {
return downloadGit(upstreamURI)
Expand Down
2 changes: 1 addition & 1 deletion pkg/upstream/replicated.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type Release struct {
Manifests map[string][]byte
}

func downloadReplicated(u *url.URL, localPath string, license *kotsv1beta1.License, sharedPassword string) (*Upstream, error) {
func downloadReplicated(u *url.URL, localPath string, license *kotsv1beta1.License) (*Upstream, error) {
var release *Release

if localPath != "" {
Expand Down
3 changes: 2 additions & 1 deletion pkg/upstream/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type WriteOptions struct {
RootDir string
CreateAppDir bool
IncludeAdminConsole bool
SharedPassword string
}

func (u *Upstream) WriteUpstream(options WriteOptions) error {
Expand All @@ -30,7 +31,7 @@ func (u *Upstream) WriteUpstream(options WriteOptions) error {
var previousValuesContent []byte

if options.IncludeAdminConsole {
adminConsoleFiles, err := generateAdminConsoleFiles(renderDir)
adminConsoleFiles, err := generateAdminConsoleFiles(renderDir, options.SharedPassword)
if err != nil {
return errors.Wrap(err, "failed to generate admin console")
}
Expand Down

0 comments on commit 0932e32

Please sign in to comment.