Skip to content

Commit

Permalink
feat: retrieve available runtimes from deployed CRs
Browse files Browse the repository at this point in the history
Fixes #190
  • Loading branch information
metacosm committed Jan 16, 2020
1 parent 2fa1570 commit 4d20cc0
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 37 deletions.
28 changes: 28 additions & 0 deletions deploy/crds/runtime.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: runtimes.halkyon.io
spec:
group: halkyon.io
versions:
- name: v1beta1
served: true
storage: true
names:
kind: Runtime
listKind: RuntimeList
plural: runtimes
singular: runtime
categories:
- all
additionalPrinterColumns:
- name: Runtime Name
type: string
JSONPath: .spec.name
- name: Version
type: string
JSONPath: .spec.version
- name: Image
type: string
JSONPath: .spec.image
scope: Cluster
98 changes: 98 additions & 0 deletions deploy/runtimes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
---
apiVersion: halkyon.io/v1beta1
kind: Runtime
metadata:
name: spring-boot-2.1.6
spec:
name: "spring-boot"
image: "quay.io/halkyonio/hal-maven-jdk"
executablePattern: "*"
version: "2.1.6.RELEASE"
generator: "https://generator.snowdrop.me/app?springbootversion={{.RuntimeVersion}}&groupid={{.GroupId}}&artifactid={{.ArtifactId}}&version={{.ProjectVersion}}&template={{.ProjectTemplate}}&packagename={{.PackageName}}&outdir={{.ArchiveName}}"
---
apiVersion: halkyon.io/v1beta1
kind: Runtime
metadata:
name: spring-boot-1.5.19
spec:
name: "spring-boot"
image: "quay.io/halkyonio/hal-maven-jdk"
executablePattern: "*"
version: "1.5.19.RELEASE"
generator: "https://generator.snowdrop.me/app?springbootversion={{.RuntimeVersion}}&groupid={{.GroupId}}&artifactid={{.ArtifactId}}&version={{.ProjectVersion}}&template={{.ProjectTemplate}}&packagename={{.PackageName}}&outdir={{.ArchiveName}}"
---
apiVersion: halkyon.io/v1beta1
kind: Runtime
metadata:
name: quarkus-1.1.1
spec:
name: "quarkus"
image: "quay.io/halkyonio/hal-maven-jdk"
executablePattern: "*-runner"
version: "1.1.1.Final"
generator: "https://code.quarkus.io/api/download?g={{.GroupId}}&a={{.ArtifactId}}&v={{.ProjectVersion}}&c={{.PackageName}}.ResourceExample"
---
apiVersion: halkyon.io/v1beta1
kind: Runtime
metadata:
name: vertx-3.8.4
spec:
name: "vert.x"
image: "quay.io/halkyonio/hal-maven-jdk"
executablePattern: "*-all"
version: "3.8.4"
generator: "https://start.vertx.io/starter.zip?vertxVersion={{.RuntimeVersion}}&groupId={{.GroupId}}&artifactId={{.ArtifactId}}&packageName={{.PackageName}}"
default: true
---
apiVersion: halkyon.io/v1beta1
kind: Runtime
metadata:
name: thorntail-2.5.0
spec:
name: "thorntail"
image: "quay.io/halkyonio/hal-maven-jdk"
executablePattern: "*-thorntail"
version: "2.5.0.Final"
generator: "http://generator.thorntail.io/generator?g={{.GroupId}}&a={{.ArtifactId}}&v={{.ProjectVersion}}&p={{.PackageName}}&sv={{.RuntimeVersion}}&d=cdi&d=jaxrs&d=microprofile-health&nested=false"
---
apiVersion: halkyon.io/v1beta1
kind: Runtime
metadata:
name: thorntail-2.4.0
spec:
name: "thorntail"
image: "quay.io/halkyonio/hal-maven-jdk"
executablePattern: "*-thorntail"
version: "2.4.0.Final"
generator: "http://generator.thorntail.io/generator?g={{.GroupId}}&a={{.ArtifactId}}&v={{.ProjectVersion}}&p={{.PackageName}}&sv={{.RuntimeVersion}}&d=cdi&d=jaxrs&d=microprofile-health&nested=false"
---
apiVersion: halkyon.io/v1beta1
kind: Runtime
metadata:
name: nodejs-12
spec:
name: "node.js"
image: "registry.access.redhat.com/ubi8/nodejs-12"
executablePattern: ""
version: "12.x"
---
apiVersion: halkyon.io/v1beta1
kind: Runtime
metadata:
name: nodejs-10
spec:
name: "node.js"
image: "registry.access.redhat.com/ubi8/nodejs-10"
executablePattern: ""
version: "10.x"
---
apiVersion: halkyon.io/v1beta1
kind: Runtime
metadata:
name: openjdk-8
spec:
name: "openjdk"
image: "registry.access.redhat.com/redhat-openjdk-18/openjdk18-openshift"
executablePattern: ""
version: "8"
---
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ require (
go.uber.org/zap v1.13.0 // indirect
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553
google.golang.org/api v0.15.0 // indirect
halkyon.io/api v1.0.0-rc.1.0.20200116120548-0fb179a1356f
halkyon.io/api v1.0.0-rc.2
halkyon.io/operator-framework v1.0.0-beta.2
halkyon.io/plugins v1.0.0-beta.3.0.20200116121258-8bdb76ac3ddd
k8s.io/api v0.0.0-20190918195907-bd6ac527cfd2
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,8 @@ halkyon.io/api v1.0.0-rc.1 h1:H+ZOc1tWD0CAVa338J8gZ7W8Mutf7N/qKhSYFnuOWsg=
halkyon.io/api v1.0.0-rc.1/go.mod h1:bCOZh54+rJ4SQad0L0OMO0B+Jf7J3OtKp7SPmdLowGE=
halkyon.io/api v1.0.0-rc.1.0.20200116120548-0fb179a1356f h1:KKMsRVgfWb3FzWGdgMb1Grdl9bQpXpBgCp8jM3K+nPQ=
halkyon.io/api v1.0.0-rc.1.0.20200116120548-0fb179a1356f/go.mod h1:bCOZh54+rJ4SQad0L0OMO0B+Jf7J3OtKp7SPmdLowGE=
halkyon.io/api v1.0.0-rc.2 h1:O13sEG1aZW0jtm6jEfEeJ0ZPgSkLhIQZsr+iQOO7c2E=
halkyon.io/api v1.0.0-rc.2/go.mod h1:bCOZh54+rJ4SQad0L0OMO0B+Jf7J3OtKp7SPmdLowGE=
halkyon.io/operator-framework v1.0.0-beta.2 h1:snG0Y2IIbX1JgYYkcWMhdmWCGeXvb9T4kb13z9EoN9o=
halkyon.io/operator-framework v1.0.0-beta.2/go.mod h1:vB4euwqnSltCyaAXhiqLCcwyFJ40479HZsohtDW4bLc=
halkyon.io/plugins v1.0.0-beta.3.0.20200116121258-8bdb76ac3ddd h1:eWVzdD+RABo2kAcLuIdNkHnDIdgLKFkfnUIeeMNLPgc=
Expand Down
72 changes: 36 additions & 36 deletions pkg/controller/component/runtimes.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,61 +3,61 @@ package component
import (
"fmt"
"halkyon.io/api/component/v1beta1"
"halkyon.io/api/runtime/clientset/versioned"
v1beta12 "halkyon.io/api/runtime/clientset/versioned/typed/runtime/v1beta1"
halkyon "halkyon.io/api/v1beta1"
framework "halkyon.io/operator-framework"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const (
supervisorContainerName = "copy-supervisord"
supervisorImageId = "supervisord"
latestVersionTag = "latest"
)

// todo: extract into configuration file
var registry = RuntimeRegistry{
runtimes: map[string]runtimeVersions{
"spring-boot": newRuntime("quay.io/halkyonio/hal-maven-jdk", "*"),
"vert.x": newRuntime("quay.io/halkyonio/hal-maven-jdk", "*-all"),
"quarkus": newRuntime("quay.io/halkyonio/hal-maven-jdk", "*-runner"),
"thorntail": newRuntime("quay.io/halkyonio/hal-maven-jdk", "*-thorntail"),
"openjdk8": newRuntime("registry.access.redhat.com/redhat-openjdk-18/openjdk18-openshift", ""),
"node.js": newRuntime("nodeshift/centos7-s2i-nodejs", ""),
supervisorImageId: newRuntime("quay.io/halkyonio/supervisord", ""),
},
}
var runtimesClient v1beta12.RuntimeInterface

type Runtime struct {
RegistryRef string
defaultEnv map[string]string
}

type RuntimeRegistry struct {
runtimes map[string]runtimeVersions
}

type runtimeVersions struct {
defaultVersion Runtime
}

func newRuntime(ref, jarPattern string) runtimeVersions {
return runtimeVersions{defaultVersion: Runtime{RegistryRef: ref, defaultEnv: map[string]string{"JARPATTERN": jarPattern}}}
}
func getImageInfo(component v1beta1.ComponentSpec) (Runtime, error) {
if component.Runtime == supervisorImageId {
return Runtime{RegistryRef: "quay.io/halkyonio/supervisord"}, nil
}

func (rv runtimeVersions) getRuntimeVersionFor(version string) Runtime {
// todo: compute image version based on runtime version
defaultVersion := rv.defaultVersion
ref := fmt.Sprintf("%s:%s", defaultVersion.RegistryRef, latestVersionTag)
runtime := Runtime{RegistryRef: ref, defaultEnv: defaultVersion.defaultEnv}
return runtime
}
if runtimesClient == nil {
runtimesClient = versioned.NewForConfigOrDie(framework.Helper.Config).HalkyonV1beta1().Runtimes()
}
list, err := runtimesClient.List(v1.ListOptions{})
if err != nil {
return Runtime{}, fmt.Errorf("couldn't retrieve available runtimes: %e", err)
}

func getImageInfo(component v1beta1.ComponentSpec) (Runtime, error) {
versions, ok := registry.runtimes[component.Runtime]
if !ok {
return Runtime{}, fmt.Errorf("unknown image identifier: %s", component.Runtime)
runtimeFound := false
knownVersions := ""
knownRuntimes := ""
for _, item := range list.Items {
if item.Spec.Name == component.Runtime {
runtimeFound = true
version := item.Spec.Version
if version == component.Version {
runtime := Runtime{RegistryRef: item.Spec.Image}
if len(item.Spec.ExecutablePattern) > 0 {
runtime.defaultEnv = map[string]string{"JARPATTERN": item.Spec.ExecutablePattern}
}
return runtime, nil
}
knownVersions += version + ", "
}
knownRuntimes += item.Name + ", "
}

return versions.getRuntimeVersionFor(component.Version), nil
if runtimeFound {
return Runtime{}, fmt.Errorf("couldn't find '%s' version for '%s' runtime, known versions: %s", component.Version, component.Runtime, knownVersions)
}
return Runtime{}, fmt.Errorf("couldn't find '%s' runtime, known runtimes: %s", component.Runtime, knownRuntimes)
}

func getSupervisor() *v1beta1.Component {
Expand Down

0 comments on commit 4d20cc0

Please sign in to comment.