Skip to content

Commit

Permalink
Merge pull request #116 from schemahero/kots
Browse files Browse the repository at this point in the history
Kots
  • Loading branch information
marccampbell committed Feb 26, 2020
2 parents 7ecc38b + 6c44141 commit a32a0f1
Show file tree
Hide file tree
Showing 8 changed files with 158 additions and 19 deletions.
34 changes: 33 additions & 1 deletion .github/workflows/build-and-test.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: "Build and test"
on:
push:
branches-ignore: [master] # master branch runs alpha-release workflow
tags-ignore: ["*"] # tags run tagged-release workflow
branches: ["*"]

jobs:
build:
Expand Down Expand Up @@ -81,3 +81,35 @@ jobs:
- run: make -C integration/tests/mysql/index-create run
- run: make -C integration/tests/mysql/primary-key-add run
- run: make -C integration/tests/mysql/primary-key-drop run

kots:
runs-on: ubuntu-latest
name: kots
needs: [test-mysql, test-postgres]
steps:
- name: Checkout
uses: actions/checkout@v1

- name: Download kubectl-schemahero binary
uses: actions/download-artifact@v1
with:
name: kubectl-schemahero
path: bin/
- run: chmod +x bin/kubectl-schemahero

- run: ./bin/kubectl-schemahero install --yaml --out-dir ./kots

- name: Lint the release
id: lint-action
uses: replicatedhq/action-kots-lint@v0.1.0
with:
replicated-app: "schemahero-enterprise"
replicated-api-token: ${{ secrets.REPLICATED_API_TOKEN }}
yaml-dir: kots
- name: Create the release
id: test-action
uses: replicatedhq/action-kots-release@v0.2.0
with:
replicated-app: "schemahero-enterprise"
replicated-api-token: ${{ secrets.REPLICATED_API_TOKEN }}
yaml-dir: kots
9 changes: 9 additions & 0 deletions kots/application.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: app.k8s.io/v1beta1
kind: Application
metadata:
name: schemahero-enterprise
labels:
app.kubernetes.io/name: schemahero-enterprise
spec:
descriptor:
links: []
18 changes: 18 additions & 0 deletions kots/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: kots.io/v1beta1
kind: Config
metadata:
name: config-sample
spec:
groups:
- name: example_settings
title: My Example Config
description: Configuration to serve as an example for creating your own
items:
- name: a_bool
title: a bool field
help_text: When enabled we will not change anything, because this is an example
type: bool
default: "0"
- name: a_text
title: a text field
type: text
18 changes: 18 additions & 0 deletions kots/preflight.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: troubleshoot.replicated.com/v1beta1
kind: Preflight
metadata:
name: schemahero-preflights
spec:
analyzers:
- clusterVersion:
outcomes:
- fail:
when: "< 1.13.0"
message: The application requires at Kubernetes 1.13.0 or later, and recommends 1.15.0.
uri: https://www.kubernetes.io
- warn:
when: "< 1.15.0"
message: Your cluster meets the minimum version of Kubernetes, but we recommend you update to 1.15.0 or later.
uri: https://kubernetes.io
- pass:
message: Your cluster meets the recommended and required versions of Kubernetes.
9 changes: 9 additions & 0 deletions kots/replicated-app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: kots.io/v1beta1
kind: Application
metadata:
name: schemahero-enterprise
spec:
title: SchemaHero Enterprise
icon: https://raw.githubusercontent.com/schemahero/schemahero-docs/0356662731945f066fe29be4a01edda481be277c/themes/hugo-whisper-theme/static/images/schemahero-logo.svga
releaseNotes: |
SchemaHero 0.8.0
32 changes: 32 additions & 0 deletions kots/support-bundle.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apiVersion: troubleshoot.replicated.com/v1beta1
kind: Collector
metadata:
name: collector-sample
spec:
collectors:
- clusterInfo: {}
- clusterResources: {}
- secret:
name: illmannered-cricket-mysql
namespace: default
key: mysql-password
- logs:
selector:
- name=nginx-ingress-microk8s
namespace: default
limits:
maxAge: 30d
maxLines: 10000
- run:
collectorName: ping-google
namespace: default
image: flungo/netutils
command: ["ping"]
args: ["www.google.com"]
timeout: 5s
- http:
collectorName: test-get
get:
url: https://api.staging.replicated.com/market/v1/echo/ip
insecureSkipVerify: false
headers: {}
29 changes: 27 additions & 2 deletions pkg/cli/schemaherokubectlcli/install.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package schemaherokubectlcli

import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path/filepath"

"github.com/schemahero/schemahero/pkg/installer"
"github.com/spf13/cobra"
Expand All @@ -27,14 +30,35 @@ func InstallCmd() *cobra.Command {
os.Exit(1)
}
}

if v.GetBool("yaml") {
manifests, err := installer.GenerateOperatorYAML(v.GetString("extensions-api"))
if err != nil {
fmt.Printf("Error: %s\n", err.Error())
return err
}

fmt.Printf("%s\n", manifests)
if v.GetString("out-dir") != "" {
if err := os.MkdirAll(v.GetString("out-dir"), 0755); err != nil {
fmt.Printf("Error: %s\n", err.Error())
return err
}

for filename, manifest := range manifests {
if err := ioutil.WriteFile(filepath.Join(v.GetString("out-dir"), filename), manifest, 0644); err != nil {
fmt.Printf("Error: %s\n", err.Error())
return err
}
}
} else {
// Write to stdout
multiDocResult := [][]byte{}
for _, manifest := range manifests {
multiDocResult = append(multiDocResult, manifest)
}

fmt.Println(string(bytes.Join(multiDocResult, []byte("\n---\n"))))
}
return nil
}
if err := installer.InstallOperator(); err != nil {
Expand All @@ -47,7 +71,8 @@ func InstallCmd() *cobra.Command {
},
}

cmd.Flags().Bool("yaml", false, "Is present, don't install the operator, just generate the yaml")
cmd.Flags().Bool("yaml", false, "If present, don't install the operator, just generate the yaml")
cmd.Flags().String("out-dir", "", "If present and --yaml also specified, write all of the manifests to this directory")
cmd.Flags().String("extensions-api", "", "version of apiextensions.k8s.io to generate. if unset, will detect best version from kubernetes version")

return cmd
Expand Down
28 changes: 12 additions & 16 deletions pkg/installer/installer.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package installer

import (
"bytes"

"strings"

"github.com/blang/semver"
Expand All @@ -11,8 +9,8 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client/config"
)

func GenerateOperatorYAML(requestedExtensionsAPIVersion string) ([]byte, error) {
manifests := [][]byte{}
func GenerateOperatorYAML(requestedExtensionsAPIVersion string) (map[string][]byte, error) {
manifests := map[string][]byte{}

useExtensionsV1Beta1 := false
if requestedExtensionsAPIVersion == "v1beta1" {
Expand All @@ -23,59 +21,57 @@ func GenerateOperatorYAML(requestedExtensionsAPIVersion string) ([]byte, error)
if err != nil {
return nil, errors.Wrap(err, "failed to get databases crd")
}
manifests = append(manifests, manifest)
manifests["databases_crd.yaml"] = manifest

manifest, err = tablesCRDYAML(useExtensionsV1Beta1)
if err != nil {
return nil, errors.Wrap(err, "failed to get tables crd")
}
manifests = append(manifests, manifest)
manifests["tables_crd.yaml"] = manifest

manifest, err = migrationsCRDYAML(useExtensionsV1Beta1)
if err != nil {
return nil, errors.Wrap(err, "failed to get migrations crd")
}
manifests = append(manifests, manifest)
manifests["migrations_crd.yaml"] = manifest

manifest, err = clusterRoleYAML()
if err != nil {
return nil, errors.Wrap(err, "failed to get cluster role")
}
manifests = append(manifests, manifest)
manifests["cluster-role.yaml"] = manifest

manifest, err = clusterRoleBindingYAML()
if err != nil {
return nil, errors.Wrap(err, "failed to get cluster binding role")
}
manifests = append(manifests, manifest)
manifests["cluster-role-binding.yaml"] = manifest

manifest, err = namespaceYAML()
if err != nil {
return nil, errors.Wrap(err, "failed to get namespace")
}
manifests = append(manifests, manifest)
manifests["namespace.yaml"] = manifest

manifest, err = serviceYAML()
if err != nil {
return nil, errors.Wrap(err, "failed to get service")
}
manifests = append(manifests, manifest)
manifests["service.yaml"] = manifest

manifest, err = secretYAML()
if err != nil {
return nil, errors.Wrap(err, "failed to get secret")
}
manifests = append(manifests, manifest)
manifests["secret.yaml"] = manifest

manifest, err = managerYAML()
if err != nil {
return nil, errors.Wrap(err, "failed to get manager")
}
manifests = append(manifests, manifest)

multiDocResult := bytes.Join(manifests, []byte("\n---\n"))
manifests["manager.yaml"] = manifest

return multiDocResult, nil
return manifests, nil
}

func InstallOperator() error {
Expand Down

0 comments on commit a32a0f1

Please sign in to comment.