Skip to content

Commit a94ae52

Browse files
Merge pull request #393 from onepanelio/feat/provider-specific-config
feat: Add support for ResourceRequirements in node pools
2 parents 46f4465 + a8958b0 commit a94ae52

File tree

5 files changed

+227
-123
lines changed

5 files changed

+227
-123
lines changed

db/20200704151301_update_cvat_workspace_template.go renamed to db/go/20200704151301_update_cvat_workspace_template.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
v1 "github.com/onepanelio/core/pkg"
66
uid2 "github.com/onepanelio/core/pkg/util/uid"
77
"github.com/pressly/goose"
8-
"time"
98
)
109

1110
const cvatWorkspaceTemplate3 = `# Docker containers that are part of the Workspace
@@ -128,14 +127,20 @@ func init() {
128127
// Up20200704151301 updates the CVAT template to a new version.
129128
func Up20200704151301(tx *sql.Tx) error {
130129
// This code is executed when the migration is applied.
131-
132-
time.Sleep(2 * time.Second)
133-
134130
client, err := getClient()
135131
if err != nil {
136132
return err
137133
}
138134

135+
migrationsRan, err := getRanSQLMigrations(client)
136+
if err != nil {
137+
return err
138+
}
139+
140+
if _, ok := migrationsRan[20200704151301]; ok {
141+
return nil
142+
}
143+
139144
namespaces, err := client.ListOnepanelEnabledNamespaces()
140145
if err != nil {
141146
return err

pkg/config.go

Lines changed: 0 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -2,121 +2,13 @@ package v1
22

33
import (
44
"encoding/base64"
5-
"fmt"
65
"github.com/onepanelio/core/pkg/util"
7-
"github.com/onepanelio/core/pkg/util/ptr"
86
log "github.com/sirupsen/logrus"
97
"google.golang.org/grpc/codes"
108
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
119
"sigs.k8s.io/yaml"
12-
"strings"
1310
)
1411

15-
// SystemConfig is configuration loaded from kubernetes config and secrets that includes information about the
16-
// database, server, etc.
17-
type SystemConfig map[string]string
18-
19-
// NewSystemConfig creates a System config by getting the required data from a ConfigMap and Secret
20-
func NewSystemConfig(configMap *ConfigMap, secret *Secret) (config SystemConfig, err error) {
21-
config = configMap.Data
22-
23-
databaseUsername, err := base64.StdEncoding.DecodeString(secret.Data["databaseUsername"])
24-
if err != nil {
25-
return
26-
}
27-
config["databaseUsername"] = string(databaseUsername)
28-
29-
databasePassword, err := base64.StdEncoding.DecodeString(secret.Data["databasePassword"])
30-
if err != nil {
31-
return
32-
}
33-
config["databasePassword"] = string(databasePassword)
34-
35-
return
36-
}
37-
38-
// GetValue returns the value in the underlying map if it exists, otherwise nil is returned
39-
// If the value does not exist, it is also logged.
40-
func (s SystemConfig) GetValue(name string) *string {
41-
value, ok := s[name]
42-
if !ok {
43-
log.WithFields(log.Fields{
44-
"Method": "SystemConfig.GetValue",
45-
"Name": name,
46-
"Error": "does not exist",
47-
})
48-
49-
return nil
50-
}
51-
52-
return &value
53-
}
54-
55-
// Domain gets the ONEPANEL_DOMAIN value, or nil.
56-
func (s SystemConfig) Domain() *string {
57-
return s.GetValue("ONEPANEL_DOMAIN")
58-
}
59-
60-
// APIURL gets the ONEPANEL_API_URL, or nil.
61-
func (s SystemConfig) APIURL() *string {
62-
return s.GetValue("ONEPANEL_API_URL")
63-
}
64-
65-
// APIProtocol returns either http:// or https:// or nil.
66-
// It is based on the ONEPANEL_API_URL config value and checks if it has https or http
67-
func (s SystemConfig) APIProtocol() *string {
68-
url := s.APIURL()
69-
if url == nil {
70-
return nil
71-
}
72-
73-
if strings.HasPrefix(*url, "https://") {
74-
return ptr.String("https://")
75-
}
76-
77-
return ptr.String("http://")
78-
}
79-
80-
// FQDN gets the ONEPANEL_FQDN value or nil.
81-
func (s SystemConfig) FQDN() *string {
82-
return s.GetValue("ONEPANEL_FQDN")
83-
}
84-
85-
// NodePoolLabel gets the applicationNodePoolLabel from the config or returns nil.
86-
func (s SystemConfig) NodePoolLabel() (label *string) {
87-
return s.GetValue("applicationNodePoolLabel")
88-
}
89-
90-
// NodePoolOptions loads and parses the applicationNodePoolOptions from the config.
91-
// If there is no data, an error is returned.
92-
func (s SystemConfig) NodePoolOptions() (options []*ParameterOption, err error) {
93-
data := s.GetValue("applicationNodePoolOptions")
94-
if data == nil {
95-
return nil, fmt.Errorf("no nodePoolOptions in config")
96-
}
97-
98-
if err = yaml.Unmarshal([]byte(*data), &options); err != nil {
99-
return
100-
}
101-
102-
return
103-
}
104-
105-
// DatabaseDriverName gets the databaseDriverName value, or nil.
106-
func (s SystemConfig) DatabaseDriverName() *string {
107-
return s.GetValue("databaseDriverName")
108-
}
109-
110-
// DatabaseConnection returns system config information to connect to a database
111-
func (s SystemConfig) DatabaseConnection() (driverName, dataSourceName string) {
112-
dataSourceName = fmt.Sprintf("host=%v user=%v password=%v dbname=%v sslmode=disable",
113-
s["databaseHost"], s["databaseUsername"], s["databasePassword"], s["databaseName"])
114-
115-
driverName = *s.DatabaseDriverName()
116-
117-
return
118-
}
119-
12012
func (c *Client) getConfigMap(namespace, name string) (configMap *ConfigMap, err error) {
12113
cm, err := c.CoreV1().ConfigMaps(namespace).Get(name, metav1.GetOptions{})
12214
if err != nil {

pkg/config_types.go

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,141 @@
11
package v1
22

33
import (
4+
"encoding/base64"
5+
"fmt"
6+
"github.com/onepanelio/core/pkg/util/ptr"
7+
log "github.com/sirupsen/logrus"
48
corev1 "k8s.io/api/core/v1"
9+
"sigs.k8s.io/yaml"
510
"strings"
611
)
712

13+
// SystemConfig is configuration loaded from kubernetes config and secrets that includes information about the
14+
// database, server, etc.
15+
type SystemConfig map[string]string
16+
17+
// NodePoolOption extends ParameterOption to support resourceRequirements
18+
type NodePoolOption struct {
19+
ParameterOption
20+
Resources corev1.ResourceRequirements
21+
}
22+
23+
// NewSystemConfig creates a System config by getting the required data from a ConfigMap and Secret
24+
func NewSystemConfig(configMap *ConfigMap, secret *Secret) (config SystemConfig, err error) {
25+
config = configMap.Data
26+
27+
databaseUsername, err := base64.StdEncoding.DecodeString(secret.Data["databaseUsername"])
28+
if err != nil {
29+
return
30+
}
31+
config["databaseUsername"] = string(databaseUsername)
32+
33+
databasePassword, err := base64.StdEncoding.DecodeString(secret.Data["databasePassword"])
34+
if err != nil {
35+
return
36+
}
37+
config["databasePassword"] = string(databasePassword)
38+
39+
return
40+
}
41+
42+
// GetValue returns the value in the underlying map if it exists, otherwise nil is returned
43+
// If the value does not exist, it is also logged.
44+
func (s SystemConfig) GetValue(name string) *string {
45+
value, ok := s[name]
46+
if !ok {
47+
log.WithFields(log.Fields{
48+
"Method": "SystemConfig.GetValue",
49+
"Name": name,
50+
"Error": "does not exist",
51+
})
52+
53+
return nil
54+
}
55+
56+
return &value
57+
}
58+
59+
// Domain gets the ONEPANEL_DOMAIN value, or nil.
60+
func (s SystemConfig) Domain() *string {
61+
return s.GetValue("ONEPANEL_DOMAIN")
62+
}
63+
64+
// APIURL gets the ONEPANEL_API_URL, or nil.
65+
func (s SystemConfig) APIURL() *string {
66+
return s.GetValue("ONEPANEL_API_URL")
67+
}
68+
69+
// APIProtocol returns either http:// or https:// or nil.
70+
// It is based on the ONEPANEL_API_URL config value and checks if it has https or http
71+
func (s SystemConfig) APIProtocol() *string {
72+
url := s.APIURL()
73+
if url == nil {
74+
return nil
75+
}
76+
77+
if strings.HasPrefix(*url, "https://") {
78+
return ptr.String("https://")
79+
}
80+
81+
return ptr.String("http://")
82+
}
83+
84+
// FQDN gets the ONEPANEL_FQDN value or nil.
85+
func (s SystemConfig) FQDN() *string {
86+
return s.GetValue("ONEPANEL_FQDN")
87+
}
88+
89+
// NodePoolLabel gets the applicationNodePoolLabel from the config or returns nil.
90+
func (s SystemConfig) NodePoolLabel() (label *string) {
91+
return s.GetValue("applicationNodePoolLabel")
92+
}
93+
94+
// NodePoolOptions loads and parses the applicationNodePoolOptions from the config.
95+
// If there is no data, an error is returned.
96+
func (s SystemConfig) NodePoolOptions() (options []*NodePoolOption, err error) {
97+
data := s.GetValue("applicationNodePoolOptions")
98+
if data == nil {
99+
return nil, fmt.Errorf("no nodePoolOptions in config")
100+
}
101+
102+
if err = yaml.Unmarshal([]byte(*data), &options); err != nil {
103+
return
104+
}
105+
106+
return
107+
}
108+
109+
// NodePoolOptionByValue returns the nodePoolOption based on a given value
110+
func (s SystemConfig) NodePoolOptionByValue(value string) (option *NodePoolOption, err error) {
111+
options, err := s.NodePoolOptions()
112+
if err != nil {
113+
return
114+
}
115+
for _, opt := range options {
116+
if opt.Value == value {
117+
option = opt
118+
return
119+
}
120+
}
121+
return
122+
}
123+
124+
// DatabaseDriverName gets the databaseDriverName value, or nil.
125+
func (s SystemConfig) DatabaseDriverName() *string {
126+
return s.GetValue("databaseDriverName")
127+
}
128+
129+
// DatabaseConnection returns system config information to connect to a database
130+
func (s SystemConfig) DatabaseConnection() (driverName, dataSourceName string) {
131+
dataSourceName = fmt.Sprintf("host=%v user=%v password=%v dbname=%v sslmode=disable",
132+
s["databaseHost"], s["databaseUsername"], s["databasePassword"], s["databaseName"])
133+
134+
driverName = *s.DatabaseDriverName()
135+
136+
return
137+
}
138+
8139
type ArtifactRepositoryS3Config struct {
9140
KeyFormat string
10141
Bucket string

0 commit comments

Comments
 (0)