Skip to content
This repository was archived by the owner on Mar 7, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
# runner
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fyabslabs%2Frunner.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fyabslabs%2Frunner?ref=badge_shield)

## implemented executors

## executors to be implemented

- docker
- kubernetes
- shell (what shell?)

## project structure

## License
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fyabslabs%2Frunner.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fyabslabs%2Frunner?ref=badge_large)
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fyabslabs%2Frunner.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fyabslabs%2Frunner?ref=badge_large)
3 changes: 3 additions & 0 deletions common/README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Common Package

This package fakes the common Package until it's fully implemented.
70 changes: 70 additions & 0 deletions common/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright (c) 2018 VRSG | Verwaltungsrechenzentrum AG, St.Gallen
* All Rights Reserved.
*/

package common

import (
"fmt"
"io/ioutil"
"os"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

type ConfigReader interface {
Unmarshal(data []byte, o interface{}) error
}

type ValidateableConfiguration interface {
Validate() error
}

type ConfigReaderFunc func(data []byte, o interface{}) error

func (c ConfigReaderFunc) Unmarshal(data []byte, o interface{}) error {
return c(data, o)
}

func readConfigFile(configReader ConfigReader, configFile string, obj interface{}) error {
configFile = os.ExpandEnv(configFile)

if _, err := os.Stat(configFile); err != nil {
fmt.Println("CONF-3e126710", err, configFile)
return nil
}

configStr, err := ioutil.ReadFile(configFile) //nolint: gosec

if err != nil {
return status.Errorf(codes.Internal, "failed to read config file %s: %v", configFile, err)
}

configStr = []byte(os.ExpandEnv(string(configStr)))

if err := configReader.Unmarshal(configStr, obj); err != nil {
return status.Errorf(codes.Internal, "error parse config file %s: %v", configFile, err)
}

return nil
}

// ReadConfig deserializes each configfile to the target obj using the configReader
// env vars are replaced in the file path
func ReadConfig(configReader ConfigReader, obj interface{}, configFiles ...string) error {
for _, cf := range configFiles {
if err := readConfigFile(configReader, cf, obj); err != nil {
return err
}
}

if validateable, ok := obj.(ValidateableConfiguration); ok {
if err := validateable.Validate(); err != nil {
return err
}
}

return nil
}
58 changes: 58 additions & 0 deletions common/logging/logging.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
Copyright 2018 tribock.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package logging

import (
"fmt"

"github.com/sirupsen/logrus"
)

const (
fieldLogID = "abraxasLogID"
)

func WithError(id string, err error) *logrus.Entry {
return WithID(id).WithError(err)
}

func WithID(id string) *logrus.Entry {
return logrus.WithField(fieldLogID, id)
}

func WithIDFields(id string, fields ...interface{}) *logrus.Entry {
m := Pairs(fields...)
m[fieldLogID] = id
return logrus.WithFields(m)
}

func Pairs(kv ...interface{}) map[string]interface{} {
if len(kv)%2 == 1 {
panic(fmt.Sprintf("Pairs got the odd number of input pairs for metadata: %d", len(kv)))
}

v := map[string]interface{}{}
var key string
for i, s := range kv {
if i%2 == 0 {
key = fmt.Sprint(s)
continue
}

v[key] = s
}
return v
}
24 changes: 24 additions & 0 deletions common/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package common

// JobStatus that represents the Status of a Job
type JobStatus int

// JobStatus implementation as enum
const (
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is aligned to the yabs/api, looks good

UNKNOWN JobStatus = iota
CREATED
PENDING
RUNNING
FAILED
SUCCESS
CANCELED
SKIPPED
MANUAL
STUCK
RETRIED
PAUSED
SUSPENDED
)

type Job struct {
}
20 changes: 20 additions & 0 deletions configuration/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package configuration

import (
"git.workshop21.ch/go/abraxas/configuration/yaml"
)

type Config struct {
Env string
GRPCPort string
GatewayPort string
ImageBaseUrl string
HttpsPort int32
}

func ReadConfig() (*Config, error) {
config := &Config{}
err := yaml.ReadConfig(config,
"./config/config.yaml")
return config, err
}
21 changes: 21 additions & 0 deletions configuration/yaml/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (c) 2018 VRSG | Verwaltungsrechenzentrum AG, St.Gallen
* All Rights Reserved.
*/

package yaml

import (
"git.workshop21.ch/go/abraxas/configuration"
"github.com/ghodss/yaml"
)

var ConfigReader = configuration.ConfigReaderFunc(yamlUnmarshalNoOpts)

func yamlUnmarshalNoOpts(y []byte, o interface{}) error {
return yaml.Unmarshal(y, o)
}

func ReadConfig(obj interface{}, configFiles ...string) error {
return configuration.ReadConfig(ConfigReader, obj, configFiles...)
}
5 changes: 5 additions & 0 deletions executors/engine.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package executors

type ExecutionEngine struct {
Executors []Executor
}
16 changes: 16 additions & 0 deletions executors/executor_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package executors

import (
"github.com/yabslabs/runner/common"
"github.com/yabslabs/runner/executors/kubernetes"
"github.com/yabslabs/runner/runner"
)

var types = []Executor{&kubernetes.KubernetesExecutor{}}

type Executor interface {
GetKind() string
GetStatus() runner.RunnerStatus
GetJobStatus() common.JobStatus
Run(common.Job) common.JobStatus
}
Loading