Skip to content

Commit

Permalink
KOTS to alpha tag
Browse files Browse the repository at this point in the history
  • Loading branch information
marccampbell committed Feb 28, 2020
1 parent 7a1d1f1 commit d5fa150
Show file tree
Hide file tree
Showing 6 changed files with 254 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-and-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ jobs:
env:
SHA: $(echo ${GITHUB_SHA} | cut -c1-7)

- run: ./bin/kubectl-schemahero install --yaml --out-dir=./kots --enterprise --namespace="repl{{ Namespace }}"
- run: ./bin/kubectl-schemahero install --yaml --out-dir=./kots --enterprise --namespace="repl{{ Namespace }}" --enterprise-tag=alpha
env:
SHA: $(echo ${GITHUB_SHA} | cut -c1-7)

Expand Down
4 changes: 4 additions & 0 deletions kots/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ service.yaml
namespace.yaml
secret.yaml
manager.yaml
hero-web.yaml
hero-web-service.yaml
hero-api.yaml
hero-api-service.yaml
3 changes: 2 additions & 1 deletion pkg/cli/schemaherokubectlcli/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func InstallCmd() *cobra.Command {
}

if v.GetBool("yaml") {
manifests, err := installer.GenerateOperatorYAML(v.GetString("extensions-api"), v.GetBool("enterprise"), v.GetString("namespace"))
manifests, err := installer.GenerateOperatorYAML(v.GetString("extensions-api"), v.GetBool("enterprise"), v.GetString("enterprise-tag"), v.GetString("namespace"))
if err != nil {
fmt.Printf("Error: %s\n", err.Error())
return err
Expand Down Expand Up @@ -75,6 +75,7 @@ func InstallCmd() *cobra.Command {
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")
cmd.Flags().Bool("enterprise", false, "If preset, generate enterprise YAML with KOTS template functions. This probably isn't what you want")
cmd.Flags().String("enterprise-tag", "latest", "the tag of the enterprise images to include")
cmd.Flags().StringP("namespace", "n", "schemahero-system", "The namespace to install SchemaHero Operator into")

return cmd
Expand Down
113 changes: 113 additions & 0 deletions pkg/installer/enterprise_api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package installer

import (
"bytes"
"fmt"

"github.com/pkg/errors"
"github.com/schemahero/schemahero/pkg/client/schemaheroclientset/scheme"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime/serializer/json"
)

func heroAPIServiceYAML(namespace string) ([]byte, error) {
s := json.NewYAMLSerializer(json.DefaultMetaFactory, scheme.Scheme, scheme.Scheme)
var result bytes.Buffer
if err := s.Encode(heroAPIService(namespace), &result); err != nil {
return nil, errors.Wrap(err, "failed to marshal hero api service")
}

return result.Bytes(), nil
}

func heroAPIService(namespace string) *corev1.Service {
return &corev1.Service{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Kind: "Service",
},
ObjectMeta: metav1.ObjectMeta{
Name: "hero-api",
Namespace: namespace,
Labels: map[string]string{
"app": "hero-api",
},
},
Spec: corev1.ServiceSpec{
Selector: map[string]string{
"app": "hero-api",
},
Ports: []corev1.ServicePort{
{
Port: 3000,
Name: "http",
},
},
Type: corev1.ServiceTypeClusterIP,
},
}
}

func heroAPIYAML(namespace string, tag string) ([]byte, error) {
s := json.NewYAMLSerializer(json.DefaultMetaFactory, scheme.Scheme, scheme.Scheme)
var result bytes.Buffer
if err := s.Encode(heroAPI(namespace, tag), &result); err != nil {
return nil, errors.Wrap(err, "failed to marshal hero api")
}

return result.Bytes(), nil
}

func heroAPI(namespace string, tag string) *appsv1.Deployment {
return &appsv1.Deployment{
TypeMeta: metav1.TypeMeta{
APIVersion: "apps/v1",
Kind: "Deployment",
},
ObjectMeta: metav1.ObjectMeta{
Name: "schemahero-api",
Namespace: namespace,
},
Spec: appsv1.DeploymentSpec{
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"app": "hero-api",
},
},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"app": "hero-api",
},
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Image: fmt.Sprintf(`repl{{ LocalImageName "registry.replicated.com/schemahero-enterprise/hero-api:%s"}}`, tag),
ImagePullPolicy: corev1.PullAlways,
Name: "hero-api",
Command: []string{
"/go/src/github.com/schemahero/hero-web/api/bin/hero-api",
"run",
},
Env: []corev1.EnvVar{
{
Name: "FRONTEND_URL",
Value: "http://localhost:8888",
},
},
Ports: []corev1.ContainerPort{
{
ContainerPort: 3000,
Name: "http",
},
},
},
},
},
},
},
}
}
108 changes: 108 additions & 0 deletions pkg/installer/enterprise_web.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package installer

import (
"bytes"
"fmt"

"github.com/pkg/errors"
"github.com/schemahero/schemahero/pkg/client/schemaheroclientset/scheme"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/serializer/json"
)

func heroWebServiceYAML(namespace string) ([]byte, error) {
s := json.NewYAMLSerializer(json.DefaultMetaFactory, scheme.Scheme, scheme.Scheme)
var result bytes.Buffer
if err := s.Encode(heroWebService(namespace), &result); err != nil {
return nil, errors.Wrap(err, "failed to marshal hero web service")
}

return result.Bytes(), nil
}

func heroWebService(namespace string) *corev1.Service {
return &corev1.Service{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Kind: "Service",
},
ObjectMeta: metav1.ObjectMeta{
Name: "hero-web",
Namespace: namespace,
Labels: map[string]string{
"app": "hero-web",
},
},
Spec: corev1.ServiceSpec{
Selector: map[string]string{
"app": "hero-web",
},
Ports: []corev1.ServicePort{
{
Port: 3000,
Name: "http",
},
},
Type: corev1.ServiceTypeClusterIP,
},
}
}

func heroWebYAML(namespace string, tag string) ([]byte, error) {
s := json.NewYAMLSerializer(json.DefaultMetaFactory, scheme.Scheme, scheme.Scheme)
var result bytes.Buffer
if err := s.Encode(heroWeb(namespace, tag), &result); err != nil {
return nil, errors.Wrap(err, "failed to marshal hero web")
}

return result.Bytes(), nil
}

func heroWeb(namespace string, tag string) *appsv1.Deployment {
return &appsv1.Deployment{
TypeMeta: metav1.TypeMeta{
APIVersion: "apps/v1",
Kind: "Deployment",
},
ObjectMeta: metav1.ObjectMeta{
Name: "schemahero-web",
Namespace: namespace,
},
Spec: appsv1.DeploymentSpec{
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"app": "hero-web",
},
},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"app": "hero-web",
},
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Image: fmt.Sprintf(`repl{{ LocalImageName "registry.replicated.com/schemahero-enterprise/hero-web:%s"}}`, tag),
ImagePullPolicy: corev1.PullAlways,
Name: "hero-web",
Command: []string{
"/bin/bash",
"-c",
"envsubst '$$ENV' < /etc/nginx/conf.d/default.template > /etc/nginx/conf.d/default.conf && exec nginx -g 'daemon off;'",
},
Env: []corev1.EnvVar{
{
Name: "ENV",
Value: "enterprise",
},
},
},
},
},
},
},
}
}
27 changes: 26 additions & 1 deletion pkg/installer/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client/config"
)

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

useExtensionsV1Beta1 := false
Expand Down Expand Up @@ -73,6 +73,31 @@ func GenerateOperatorYAML(requestedExtensionsAPIVersion string, isEnterprise boo
}
manifests["manager.yaml"] = manifest

if isEnterprise {
manifest, err = heroAPIYAML(namespace, enterpriseTag)
if err != nil {
return nil, errors.Wrap(err, "failed to get hero api")
}
manifests["hero-api.yaml"] = manifest

manifest, err = heroAPIServiceYAML(namespace)
if err != nil {
return nil, errors.Wrap(err, "failed to get hero api service")
}
manifests["hero-api-service.yaml"] = manifest

manifest, err = heroWebYAML(namespace, enterpriseTag)
if err != nil {
return nil, errors.Wrap(err, "failed to get hero web")
}
manifests["hero-web.yaml"] = manifest

manifest, err = heroWebServiceYAML(namespace)
if err != nil {
return nil, errors.Wrap(err, "failed to get hero web service")
}
manifests["hero-web-service.yaml"] = manifest
}
return manifests, nil
}

Expand Down

0 comments on commit d5fa150

Please sign in to comment.