-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(kubernetes): add support for Custom Resources (#117)
* feat(helm): add CRD definition and related access policy * feat(helm): add sample Application manifest * docs(crd): update accordingly * feat(crd): make icon non-required field * feat(kubernetes): add kubernetes custom resource type * refactor(api): simplify getting kubernetes client * feat(kubernetes): add support for kubernetes crds * style(go-fmt): apply formatter * docs(comments): minor changes * style(golang): just to match how it is used in ingresses file * fix(client): process error
- Loading branch information
Showing
16 changed files
with
433 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{{- if .Values.createCRAppSample }} | ||
|
||
apiVersion: hajimari.io/v1alpha1 | ||
kind: Application | ||
metadata: | ||
name: hajimari-issues | ||
spec: | ||
name: Hajimari Issues | ||
group: info | ||
icon: simple-icons:github | ||
url: https://github.com/toboshii/hajimari/issues | ||
info: Submit issue to this project | ||
targetBlank: true | ||
|
||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
--- | ||
|
||
apiVersion: apiextensions.k8s.io/v1 | ||
kind: CustomResourceDefinition | ||
metadata: | ||
name: applications.hajimari.io | ||
spec: | ||
conversion: | ||
strategy: None | ||
group: hajimari.io | ||
names: | ||
kind: Application | ||
listKind: ApplicationList | ||
plural: applications | ||
singular: application | ||
preserveUnknownFields: false | ||
scope: Namespaced | ||
versions: | ||
- name: v1alpha1 | ||
served: true | ||
storage: true | ||
schema: | ||
openAPIV3Schema: | ||
type: object | ||
properties: | ||
apiVersion: | ||
type: string | ||
kind: | ||
type: string | ||
metadata: | ||
type: object | ||
spec: | ||
type: object | ||
required: | ||
- name | ||
- group | ||
- url | ||
properties: | ||
name: | ||
type: string | ||
group: | ||
type: string | ||
icon: | ||
type: string | ||
url: | ||
type: string | ||
info: | ||
type: string | ||
targetBlank: | ||
type: boolean | ||
status: | ||
type: object |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package crdapps | ||
|
||
import ( | ||
"github.com/mitchellh/mapstructure" | ||
"github.com/toboshii/hajimari/internal/annotations" | ||
"github.com/toboshii/hajimari/internal/config" | ||
"github.com/toboshii/hajimari/internal/kube/lists/crdapps" | ||
"github.com/toboshii/hajimari/internal/kube/types/v1alpha1" | ||
"github.com/toboshii/hajimari/internal/kube/wrappers" | ||
"github.com/toboshii/hajimari/internal/log" | ||
"github.com/toboshii/hajimari/internal/models" | ||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
"k8s.io/client-go/dynamic" | ||
) | ||
|
||
var ( | ||
logger = log.New() | ||
) | ||
|
||
// List struct is used for listing hajimari apps | ||
type List struct { | ||
appConfig config.Config | ||
err error // Used for forwarding errors | ||
items []models.AppGroup | ||
dynClient dynamic.Interface | ||
} | ||
|
||
// NewList func creates a new instance of apps lister | ||
func NewList(dynClient dynamic.Interface, appConfig config.Config) *List { | ||
return &List{ | ||
appConfig: appConfig, | ||
dynClient: dynClient, | ||
} | ||
} | ||
|
||
// Populate function that populates a list of hajimari apps from ingresses in selected namespaces | ||
func (al *List) Populate(namespaces ...string) *List { | ||
appsList, err := crdapps.NewList(al.dynClient, al.appConfig). | ||
Populate(namespaces...). | ||
Get() | ||
|
||
// Apply Instance filter | ||
if len(al.appConfig.InstanceName) != 0 { | ||
appsList, err = crdapps.NewList(al.dynClient, al.appConfig, appsList...). | ||
Get() | ||
} | ||
|
||
if err != nil { | ||
al.err = err | ||
} | ||
|
||
al.items = appsToHajimariApps(appsList) | ||
|
||
return al | ||
} | ||
|
||
// Get function returns the apps currently present in List | ||
func (al *List) Get() ([]models.AppGroup, error) { | ||
return al.items, al.err | ||
} | ||
|
||
func appsToHajimariApps(apps []unstructured.Unstructured) (appGroups []models.AppGroup) { | ||
for _, app := range apps { | ||
name := app.GetName() | ||
namespace := app.GetNamespace() | ||
|
||
logger.Debugf("Found apps with Name '%v' in Namespace '%v'", name, namespace) | ||
|
||
appObj := v1alpha1.Application{} | ||
err := mapstructure.Decode(app.UnstructuredContent(), &appObj) | ||
if err != nil { | ||
logger.Error("Could not unmarshall object: %s/", name, namespace) | ||
} | ||
|
||
wrapper := wrappers.NewAppWrapper(&appObj) | ||
|
||
groupMap := make(map[string]int, len(appGroups)) | ||
for i, v := range appGroups { | ||
groupMap[v.Group] = i | ||
} | ||
|
||
if _, ok := groupMap[wrapper.GetGroup()]; !ok { | ||
appGroups = append(appGroups, models.AppGroup{ | ||
Group: wrapper.GetGroup(), | ||
}) | ||
} | ||
|
||
appMap := make(map[string]int, len(appGroups)) | ||
for i, v := range appGroups { | ||
appMap[v.Group] = i | ||
} | ||
|
||
if i, ok := appMap[wrapper.GetGroup()]; ok { | ||
appGroups[i].Apps = append(appGroups[i].Apps, models.App{ | ||
Name: wrapper.GetName(), | ||
Icon: wrapper.GetAnnotationValue(annotations.HajimariIconAnnotation), | ||
URL: wrapper.GetURL(), | ||
TargetBlank: wrapper.GetTargetBlank(), | ||
Info: wrapper.GetInfo(), | ||
}) | ||
} | ||
|
||
} | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.