first version
This commit is contained in:
12
pkg/config/ansible_playbook_config.go
Normal file
12
pkg/config/ansible_playbook_config.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/apenella/go-ansible/pkg/options"
|
||||
"github.com/apenella/go-ansible/pkg/playbook"
|
||||
)
|
||||
|
||||
type AnsiblePlaybookConfig struct {
|
||||
ConnectionOptions options.AnsibleConnectionOptions
|
||||
PrivilegeEscalationOptions options.AnsiblePrivilegeEscalationOptions
|
||||
PlaybookOptions playbook.AnsiblePlaybookOptions
|
||||
}
|
||||
66
pkg/config/config.go
Normal file
66
pkg/config/config.go
Normal file
@@ -0,0 +1,66 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/ilyakaznacheev/cleanenv"
|
||||
)
|
||||
|
||||
type Host struct {
|
||||
Hostname string `yaml:"hostname"`
|
||||
Ip string `yaml:"ip"`
|
||||
Roles []string `yaml:"roles"`
|
||||
User string `yaml:"user"`
|
||||
Password string `yaml:"password"`
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
DataDir string
|
||||
Credentials struct {
|
||||
User string `yaml:"user"`
|
||||
Password string `yaml:"password"`
|
||||
AskSudoPassword bool `yaml:"ask_sudo_password"`
|
||||
PrivateKeyFile string `yaml:"private_key_file"`
|
||||
} `yaml:"credentials"`
|
||||
|
||||
Hosts []Host `yaml:"hosts"`
|
||||
|
||||
Orchestrator Orchestrator `yaml:"orchestrator"`
|
||||
|
||||
Modules struct {
|
||||
AdminPassword string `yaml:"admin_password"`
|
||||
AdditionalRepositories interface{} `yaml:"additional_repositories"`
|
||||
Additional Additional `yaml:"additional"`
|
||||
Observability Observability `yaml:"observability"`
|
||||
Registry Registry `yaml:"registry"`
|
||||
Cicd Cicd `yaml:"cicd"`
|
||||
SecretsStorage SecretsStorage `yaml:"secrets_storage"`
|
||||
} `yaml:"modules"`
|
||||
|
||||
Repositories string
|
||||
Releases string
|
||||
}
|
||||
|
||||
var instance *Config
|
||||
|
||||
func CreateConfig(configPath string, dataDir string, password string) *Config {
|
||||
instance = &Config{}
|
||||
instance.DataDir = dataDir
|
||||
|
||||
if err := cleanenv.ReadConfig(configPath, instance); err != nil {
|
||||
helper, _ := cleanenv.GetDescription(instance, nil)
|
||||
panic(fmt.Sprintf("%s\n%s", helper, err))
|
||||
}
|
||||
|
||||
if password != "" {
|
||||
instance.Credentials.Password = password
|
||||
}
|
||||
|
||||
generateCreds(instance)
|
||||
|
||||
return instance
|
||||
}
|
||||
|
||||
func GetConfig() *Config {
|
||||
return instance
|
||||
}
|
||||
37
pkg/config/modules_additional.go
Normal file
37
pkg/config/modules_additional.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package config
|
||||
|
||||
type Additional struct {
|
||||
CertManager struct {
|
||||
Install bool `yaml:"install"`
|
||||
DnsServers []string `yaml:"dns_servers" env-default:"[8.8.8.8,1.1.1.1]"`
|
||||
AccountEmail string `yaml:"account_email"`
|
||||
} `yaml:"cert_manager"`
|
||||
|
||||
Ingress struct {
|
||||
Type string `yaml:"type" env-default:"nginx"`
|
||||
Install bool `yaml:"install" env-default:"false"`
|
||||
InsecurePort int `yaml:"insecure_port" env-default:"80"`
|
||||
SecurePort int `yaml:"secure_port" env-default:"443"`
|
||||
IngressClassName string `yaml:"ingress_class_name" env-default:"nginx"`
|
||||
HostNetwork string `yaml:"host_network" env-default:"false"`
|
||||
} `yaml:"ingress"`
|
||||
|
||||
LoadBalancer struct {
|
||||
Type string `yaml:"type" env-default:"metallb"`
|
||||
Install bool `yaml:"install"`
|
||||
} `yaml:"load_balancer"`
|
||||
|
||||
Storage struct {
|
||||
LocalPathProvisioner struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
StorageClassName string `yaml:"storage_class_name" env-default:"local-path"`
|
||||
ReclaimPolicy string `yaml:"reclaim_policy" env-default:"Delete"`
|
||||
} `yaml:"local_path_provisioner"`
|
||||
Longhorn struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
} `yaml:"longhorn"`
|
||||
SecretsStoreCsiDriver struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
} `yaml:"secrets_store_csi_driver"`
|
||||
} `yaml:"storage"`
|
||||
}
|
||||
29
pkg/config/modules_cicd.go
Normal file
29
pkg/config/modules_cicd.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package config
|
||||
|
||||
type Cicd struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
ArgoCd struct {
|
||||
AdminPassword string
|
||||
Ha struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
Autoscaling bool `yaml:"autoscaling"`
|
||||
} `yaml:"ha"`
|
||||
Expose struct {
|
||||
Type string `yaml:"type"`
|
||||
Domain string `yaml:"domain"`
|
||||
Tls struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
} `yaml:"tls"`
|
||||
} `yaml:"expose"`
|
||||
Repositories interface{} `yaml:"repositories"`
|
||||
Rbac struct {
|
||||
AdditionalPolicies string `yaml:"additional_policies"`
|
||||
} `yaml:"argo_cd"`
|
||||
} `yaml:"argo_cd"`
|
||||
UpdatesOperator struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
} `yaml:"updates_operator"`
|
||||
Rollouts struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
} `yaml:"rollouts"`
|
||||
}
|
||||
154
pkg/config/modules_observability.go
Normal file
154
pkg/config/modules_observability.go
Normal file
@@ -0,0 +1,154 @@
|
||||
package config
|
||||
|
||||
type Observability struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
Logging Logging `yaml:"logging"`
|
||||
Tracing Tracing `yaml:"tracing"`
|
||||
Monitoring Monitoring `yaml:"monitoring"`
|
||||
Visualization Visualization `yaml:"visualization"`
|
||||
}
|
||||
|
||||
type Logging struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
Operator struct {
|
||||
Image string `yaml:"image" env-default:"kubesphere/fluent-operator"`
|
||||
Tag string `yaml:"tag" env-default:"v2.7.0"`
|
||||
InitContainer struct {
|
||||
Image string `yaml:"image" env-default:"docker"`
|
||||
Tag string `yaml:"tag" env-default:"20.10"`
|
||||
} `yaml:"initcontainer"`
|
||||
} `yaml:"operator"`
|
||||
Fluentd struct {
|
||||
Image string `yaml:"image" env-default:"kubesphere/fluentd"`
|
||||
Tag string `yaml:"tag" env-default:"v1.15.3"`
|
||||
} `yaml:"fluentd"`
|
||||
FluentBit struct {
|
||||
Image string `yaml:"image" env-default:"kubesphere/fluent-bit"`
|
||||
Tag string `yaml:"tag" env-default:"v2.2.2"`
|
||||
} `yaml:"fluent_bit"`
|
||||
Loki struct {
|
||||
Registry string `yaml:"registry" env-default:"docker.io"`
|
||||
Image string `yaml:"image" env-default:"grafana/loki"`
|
||||
Tag string `yaml:"tag" env-default:"null"`
|
||||
Persistence struct {
|
||||
StorageClass string `yaml:"storage_class" env-default:"local-path"`
|
||||
StorageSize string `yaml:"storage_size" env-default:"10Gi"`
|
||||
Retention string `yaml:"retention" env-default:"168h"`
|
||||
} `yaml:"persistence"`
|
||||
AlertManagerUrl string `yaml:"alert_manager_url" env-default:"http://observability-alert-manager:9093"`
|
||||
AdditionalRulesGroups string `yaml:"additional_rules_groups" env-default:""`
|
||||
} `yaml:"loki"`
|
||||
Events struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
Exporter struct {
|
||||
Image string `yaml:"image" env-default:"ghcr.io/resmoio/kubernetes-event-exporter"`
|
||||
Tag string `yaml:"tag" env-default:"v1.4"`
|
||||
} `yaml:"exporter"`
|
||||
Cron struct {
|
||||
Image string `yaml:"image" env-default:"bitnami/kubectl"`
|
||||
Tag string `yaml:"tag" env-default:"1.27.5-debian-11-r8"`
|
||||
Schedule string `yaml:"schedule" env-default:"*/2 * * * *"`
|
||||
} `yaml:"cron"`
|
||||
} `yaml:"events"`
|
||||
}
|
||||
|
||||
type Tracing struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
Operator struct {
|
||||
Image string `yaml:"image" env-default:"ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator"`
|
||||
Tag string `yaml:"tag" env-default:""`
|
||||
} `yaml:"operator"`
|
||||
Collector struct {
|
||||
Image string `yaml:"image" env-default:"otel/opentelemetry-collector-contrib"`
|
||||
Tag string `yaml:"tag" env-default:"0.95.0"`
|
||||
} `yaml:"collector"`
|
||||
Tempo struct {
|
||||
Image string `yaml:"image" env-default:"grafana/tempo"`
|
||||
Tag string `yaml:"tag" env-default:""`
|
||||
Retention string `yaml:"retention" env-default:"24h"`
|
||||
ListenPort int `yaml:"listen_port" env-default:"3100"`
|
||||
Persistence struct {
|
||||
StorageClass string `yaml:"storage_class" env-default:"local-path"`
|
||||
StorageSize string `yaml:"storage_size" env-default:"10Gi"`
|
||||
} `yaml:"persistence"`
|
||||
TempoQuery struct {
|
||||
Image string `yaml:"image" env-default:"grafana/tempo-query"`
|
||||
Tag string `yaml:"tag" env-default:"null"`
|
||||
ListenPort int `yaml:"listen_port" env-default:"16686"`
|
||||
} `yaml:"tempo_query"`
|
||||
} `yaml:"tempo"`
|
||||
}
|
||||
|
||||
type Monitoring struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
Prometheus struct {
|
||||
Image string `yaml:"image" env-default:"prom/prometheus"`
|
||||
Tag string `yaml:"tag" env-default:"v2.45.0"`
|
||||
ScrapeInterval string `yaml:"scrape_interval" env-default:"15s"`
|
||||
Persistence struct {
|
||||
StorageClass string `yaml:"storage_class" env-default:"local-path"`
|
||||
StorageSize string `yaml:"storage_size" env-default:"3Gi"`
|
||||
Retention string `yaml:"retention" env-default:"7d"`
|
||||
} `yaml:"persistence"`
|
||||
Operator struct {
|
||||
Image string `yaml:"image" env-default:"ghcr.io/prometheus-operator/prometheus-operator"`
|
||||
Tag string `yaml:"tag" env-default:"v0.65.2"`
|
||||
ConfigReloader struct {
|
||||
Image string `yaml:"image" env-default:"ghcr.io/prometheus-operator/prometheus-config-reloader"`
|
||||
Tag string `yaml:"tag" env-default:"v0.65.2"`
|
||||
} `yaml:"config_reloader"`
|
||||
KubeRbacProxy struct {
|
||||
Image string `yaml:"image" env-default:"bitnami/kube-rbac-proxy"`
|
||||
Tag string `yaml:"tag" env-default:"0.14.1"`
|
||||
} `yaml:"kube_rbac_proxy"`
|
||||
} `yaml:"operator"`
|
||||
} `yaml:"prometheus"`
|
||||
AlertManager struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
Image string `yaml:"image" env-default:"prom/alertmanager"`
|
||||
Tag string `yaml:"tag" env-default:"v0.26.0"`
|
||||
Route interface{} `yaml:"route"`
|
||||
Receivers interface{} `yaml:"receivers"`
|
||||
} `yaml:"alert_manager"`
|
||||
Blackbox struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
Image string `yaml:"image" env-default:"prom/blackbox-exporter"`
|
||||
Tag string `yaml:"tag" env-default:"v0.24.0"`
|
||||
additionalModules string `yaml:"routes" env-default:""`
|
||||
} `yaml:"blackbox"`
|
||||
KubeState struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
Image string `yaml:"image" env-default:"bitnami/kube-state-metrics"`
|
||||
Tag string `yaml:"tag" env-default:"2.9.2"`
|
||||
} `yaml:"kube_state"`
|
||||
Node struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
Image string `yaml:"image" env-default:"prom/node-exporter"`
|
||||
Tag string `yaml:"tag" env-default:"v1.5.0"`
|
||||
} `yaml:"node"`
|
||||
}
|
||||
|
||||
type Visualization struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
Grafana struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
Image string `yaml:"image" env-default:"grafana/grafana"`
|
||||
Tag string `yaml:"tag" env-default:"10.4.1"`
|
||||
Expose struct {
|
||||
Type string `yaml:"type" env-default:"ingress"`
|
||||
Domain string `yaml:"domain" env-default:""`
|
||||
Tls struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
}
|
||||
} `yaml:"expose"`
|
||||
Persistence struct {
|
||||
StorageClass string `yaml:"storage_class" env-default:"local-path"`
|
||||
StorageSize string `yaml:"storage_size" env-default:"2Gi"`
|
||||
} `yaml:"persistence"`
|
||||
Config struct {
|
||||
Auth string `yaml:"auth" env-default:""`
|
||||
AuthGenericAuth string `yaml:"auth_generic_auth" env-default:""`
|
||||
AdditionalDatasources interface{} `yaml:"additional_datasources"`
|
||||
} `yaml:"config"`
|
||||
} `yaml:"grafana"`
|
||||
}
|
||||
26
pkg/config/modules_registry.go
Normal file
26
pkg/config/modules_registry.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package config
|
||||
|
||||
type Registry struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
AdminPassword string
|
||||
Namespace string `yaml:"namespace" env-default:"registry"`
|
||||
Version string `yaml:"version" env-default:"v2.10.1"`
|
||||
Expose struct {
|
||||
Type string `yaml:"type" env-default:"nodePort"`
|
||||
Domain string `yaml:"domain" env-default:""`
|
||||
NodePortHttp int `yaml:"node_port_http" env-default:"30002"`
|
||||
NodePortHttps int `yaml:"node_port_https" env-default:"30003"`
|
||||
} `yaml:"expose"`
|
||||
Tls struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
} `yaml:"tls"`
|
||||
Persistence struct {
|
||||
StorageClass string `yaml:"storage_class" env-default:"local-path"`
|
||||
RegistrySize string `yaml:"registry_size" env-default:"10Gi"`
|
||||
JobserviceSize string `yaml:"jobservice_size" env-default:"1Gi"`
|
||||
DatabaseSize string `yaml:"database_size" env-default:"2Gi"`
|
||||
RedisSize string `yaml:"redis_size" env-default:"1Gi"`
|
||||
TrivySize string `yaml:"trivy_size" env-default:"5Gi"`
|
||||
} `yaml:"persistence"`
|
||||
EnabledScanner bool `yaml:"enabled_scanner"`
|
||||
}
|
||||
42
pkg/config/modules_secrets_storage.go
Normal file
42
pkg/config/modules_secrets_storage.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package config
|
||||
|
||||
type SecretsStorage struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
Image string `yaml:"image" env-default:"kubesphere/fluent-operator"`
|
||||
Tag string `yaml:"tag" env-default:"v2.7.0"`
|
||||
Expose struct {
|
||||
Type string `yaml:"type"`
|
||||
Domain string `yaml:"domain"`
|
||||
NodePort int `yaml:"node_port"`
|
||||
Tls struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
} `yaml:"tls"`
|
||||
} `yaml:"expose"`
|
||||
CsiIntegration struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
Image string `yaml:"image" env-default:"hashicorp/vault-csi-provider"`
|
||||
Tag string `yaml:"tag" env-default:"1.4.1"`
|
||||
} `yaml:"csi_integration"`
|
||||
Injector struct {
|
||||
Image string `yaml:"image" env-default:"hashicorp/vault-k8s"`
|
||||
Tag string `yaml:"tag" env-default:"1.3.1"`
|
||||
} `yaml:"injector"`
|
||||
Server struct {
|
||||
Image string `yaml:"image" env-default:"hashicorp/vault"`
|
||||
Tag string `yaml:"tag" env-default:"1.15.6"`
|
||||
Persistence struct {
|
||||
DataStorage struct {
|
||||
StorageClass string `yaml:"storage_class" env-default:"local-path"`
|
||||
Size string `yaml:"size" env-default:"10Gi"`
|
||||
} `yaml:"data_storage"`
|
||||
AuditStorage struct {
|
||||
StorageClass string `yaml:"storage_class" env-default:"local-path"`
|
||||
Size string `yaml:"size" env-default:"10Gi"`
|
||||
} `yaml:"audit_storage"`
|
||||
} `yaml:"persistence"`
|
||||
} `yaml:"server"`
|
||||
Agent struct {
|
||||
Image string `yaml:"image" env-default:"hashicorp/vault"`
|
||||
Tag string `yaml:"tag" env-default:"1.15.6"`
|
||||
} `yaml:"agent"`
|
||||
}
|
||||
31
pkg/config/orchestrator.go
Normal file
31
pkg/config/orchestrator.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package config
|
||||
|
||||
type Dns struct {
|
||||
Servers []string `yaml:"servers" env-default:"[8.8.8.8,8.8.4.4]"`
|
||||
DisableHostNameservers bool `yaml:"disable_host_nameservers" env-default:"false"`
|
||||
}
|
||||
|
||||
type Orchestrator struct {
|
||||
Version string `yaml:"version" env-default:"v1.28.0"`
|
||||
ClusterName string `yaml:"cluster_name" env-default:"k8s-cluster.local"`
|
||||
BinDir string `yaml:"bin_dir" env-default:"/usr/local/bin"`
|
||||
SysctlFilePath string `yaml:"sysctl_file_path" env-default:"/etc/sysctl.d/99-sysctl.conf"`
|
||||
LoadbalancerApiserverPort int `yaml:"loadbalancer_apiserver_port" env-default:"6443"`
|
||||
Dns Dns `yaml:"dns"`
|
||||
CloudProvider string `yaml:"cloud_provider"`
|
||||
ExgernalCloudProvider string `yaml:"external_cloud_provider"`
|
||||
ContainerEngine struct {
|
||||
Type string `yaml:"type" env-default:"containerd"`
|
||||
Install bool `yaml:"install" env-default:"true"`
|
||||
} `yaml:"container_engine"`
|
||||
PingAccessIp bool `yaml:"ping_access_ip" env-default:"true"`
|
||||
AutoRenewCertificates bool `yaml:"auto_renew_certificates" env-default:"false"`
|
||||
EventTtl string `yaml:"event_ttl" env-default:"1h0m0s"`
|
||||
PodSecurotyPolicyEnabled bool `yaml:"pod_security_policy_enabled" env-default:"false"`
|
||||
|
||||
Network struct {
|
||||
Plugin string `yaml:"plugin" env-default:"calico"`
|
||||
ServiceAddresses string `yaml:"service_addresses" env-default:"10.233.0.0/18"`
|
||||
PodsSubnet string `yaml:"pods_subnet" env-default:"10.233.64.0/18"`
|
||||
} `yaml:"network"`
|
||||
}
|
||||
18
pkg/config/utility.go
Normal file
18
pkg/config/utility.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
func getBcryptHash(input string) string {
|
||||
hashedPassword, err := bcrypt.GenerateFromPassword([]byte(input), bcrypt.DefaultCost)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return string(hashedPassword)
|
||||
}
|
||||
|
||||
func generateCreds(config *Config) {
|
||||
config.Modules.Cicd.ArgoCd.AdminPassword = getBcryptHash(config.Modules.AdminPassword)
|
||||
config.Modules.Registry.AdminPassword = config.Modules.AdminPassword
|
||||
}
|
||||
Reference in New Issue
Block a user