Skip to content
231 changes: 231 additions & 0 deletions api/config/v2alpha2/projectconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"sort"
"strings"

"github.com/bankdata/styra-controller/api/config/v2alpha3"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -449,6 +450,236 @@ func (c *ProjectConfig) OPARestartEnabled() bool {
return c.PodRestart.OPARestart.Enabled
}

// ToV2Alpha3 returns this ProjectConfig converted to a v2alpha3.ProjectConfig
func (c *ProjectConfig) ToV2Alpha3() *v2alpha3.ProjectConfig {
v2cfg3 := &v2alpha3.ProjectConfig{
ControllerClass: c.ControllerClass,
DeletionProtectionDefault: c.DeletionProtectionDefault,
ReadOnly: c.ReadOnly,
EnableDeltaBundlesDefault: c.EnableDeltaBundlesDefault,
DisableCRDWebhooks: c.DisableCRDWebhooks,
EnableMigrations: c.EnableMigrations,
DatasourceIgnorePatterns: c.DatasourceIgnorePatterns,
LogLevel: c.LogLevel,
Styra: v2alpha3.StyraConfig{
Token: c.Styra.Token,
Address: c.Styra.Address,
TokenSecretPath: c.Styra.TokenSecretPath,
},
SystemPrefix: c.SystemPrefix,
SystemSuffix: c.SystemSuffix,
SystemUserRoles: c.SystemUserRoles,
EnableStyraReconciliation: c.EnableStyraReconciliation,
EnableOPAControlPlaneReconciliation: c.EnableOPAControlPlaneReconciliation,
EnableOPAControlPlaneReconciliationTestData: c.EnableOPAControlPlaneReconciliationTestData,
}

if c.GitCredentials != nil {
v2cfg3.GitCredentials = make([]*v2alpha3.GitCredential, len(c.GitCredentials))
for i, c := range c.GitCredentials {
v2cfg3.GitCredentials[i] = &v2alpha3.GitCredential{
User: c.User,
Password: c.Password,
RepoPrefix: c.RepoPrefix,
}
}
}

if c.LeaderElection != nil {
v2cfg3.LeaderElection = &v2alpha3.LeaderElectionConfig{
LeaseDuration: c.LeaderElection.LeaseDuration,
RenewDeadline: c.LeaderElection.RenewDeadline,
RetryPeriod: c.LeaderElection.RetryPeriod,
}
}

if c.NotificationWebhooks != nil {
v2cfg3.NotificationWebhooks = &v2alpha3.NotificationWebhooksConfig{
SystemDatasourceChanged: c.NotificationWebhooks.SystemDatasourceChanged,
LibraryDatasourceChanged: c.NotificationWebhooks.LibraryDatasourceChanged,
}
}

if c.Sentry != nil {
v2cfg3.Sentry = &v2alpha3.SentryConfig{
DSN: c.Sentry.DSN,
Debug: c.Sentry.Debug,
Environment: c.Sentry.Environment,
HTTPSProxy: c.Sentry.HTTPSProxy,
}
}

if c.SSO != nil {
v2cfg3.SSO = &v2alpha3.SSOConfig{
IdentityProvider: c.SSO.IdentityProvider,
JWTGroupsClaim: c.SSO.JWTGroupsClaim,
}
}

v2cfg3.OPA = v2alpha3.OPAConfig{
DecisionLogs: v2alpha3.DecisionLog{
RequestContext: v2alpha3.RequestContext{
HTTP: v2alpha3.HTTP{
Headers: c.OPA.DecisionLogs.RequestContext.HTTP.Headers,
},
},
},
Metrics: v2alpha3.MetricsConfig{
Prometheus: v2alpha3.PrometheusMetricsConfig{
HTTP: v2alpha3.HTTPMetricsConfig{
Buckets: c.OPA.Metrics.Prometheus.HTTP.Buckets,
},
},
},
PersistBundle: c.OPA.PersistBundle,
PersistBundleDirectory: c.OPA.PersistBundleDirectory,
}

if c.OPA.BundleServer != nil {
v2cfg3.OPA.BundleServer = &v2alpha3.OPABundleServer{
URL: c.OPA.BundleServer.URL,
Path: c.OPA.BundleServer.Path,
}
}

if c.DecisionsExporter != nil {
v2cfg3.DecisionsExporter = &v2alpha3.ExporterConfig{
Enabled: c.DecisionsExporter.Enabled,
Interval: c.DecisionsExporter.Interval,
}

if c.DecisionsExporter.Kafka != nil {
v2cfg3.DecisionsExporter.Kafka = &v2alpha3.KafkaConfig{
Brokers: c.DecisionsExporter.Kafka.Brokers,
Topic: c.DecisionsExporter.Kafka.Topic,
RequiredAcks: c.DecisionsExporter.Kafka.RequiredAcks,
}

if c.DecisionsExporter.Kafka.TLS != nil {
v2cfg3.DecisionsExporter.Kafka.TLS = &v2alpha3.TLSConfig{
ClientCertificateName: c.DecisionsExporter.Kafka.TLS.ClientCertificateName,
ClientCertificate: c.DecisionsExporter.Kafka.TLS.ClientCertificate,
ClientKey: c.DecisionsExporter.Kafka.TLS.ClientKey,
RootCA: c.DecisionsExporter.Kafka.TLS.RootCA,
InsecureSkipVerify: c.DecisionsExporter.Kafka.TLS.InsecureSkipVerify,
}
}
}
}

if c.ActivityExporter != nil {
v2cfg3.ActivityExporter = &v2alpha3.ExporterConfig{
Enabled: c.ActivityExporter.Enabled,
Interval: c.ActivityExporter.Interval,
}

if c.ActivityExporter.Kafka != nil {
v2cfg3.ActivityExporter.Kafka = &v2alpha3.KafkaConfig{
Brokers: c.ActivityExporter.Kafka.Brokers,
Topic: c.ActivityExporter.Kafka.Topic,
RequiredAcks: c.ActivityExporter.Kafka.RequiredAcks,
}

if c.ActivityExporter.Kafka.TLS != nil {
v2cfg3.ActivityExporter.Kafka.TLS = &v2alpha3.TLSConfig{
ClientCertificateName: c.ActivityExporter.Kafka.TLS.ClientCertificateName,
ClientCertificate: c.ActivityExporter.Kafka.TLS.ClientCertificate,
ClientKey: c.ActivityExporter.Kafka.TLS.ClientKey,
RootCA: c.ActivityExporter.Kafka.TLS.RootCA,
InsecureSkipVerify: c.ActivityExporter.Kafka.TLS.InsecureSkipVerify,
}
}
}
}

if c.PodRestart != nil {
v2cfg3.PodRestart = &v2alpha3.PodRestartConfig{}

if c.PodRestart.SLPRestart != nil {
v2cfg3.PodRestart.SLPRestart = &v2alpha3.SLPRestartConfig{
Enabled: c.PodRestart.SLPRestart.Enabled,
DeploymentType: c.PodRestart.SLPRestart.DeploymentType,
}
}

if c.PodRestart.OPARestart != nil {
v2cfg3.PodRestart.OPARestart = &v2alpha3.OPARestartConfig{
Enabled: c.PodRestart.OPARestart.Enabled,
DeploymentType: c.PodRestart.OPARestart.DeploymentType,
}
}
}

if c.OPAControlPlaneConfig != nil {
v2cfg3.OPAControlPlaneConfig = &v2alpha3.OPAControlPlaneConfig{
Address: c.OPAControlPlaneConfig.Address,
Token: c.OPAControlPlaneConfig.Token,
SystemDatasourceChanged: c.OPAControlPlaneConfig.SystemDatasourceChanged,
LibraryDatasourceChanged: c.OPAControlPlaneConfig.LibraryDatasourceChanged,
}

if c.OPAControlPlaneConfig.GitCredentials != nil {
v2cfg3.OPAControlPlaneConfig.GitCredentials = make(
[]*v2alpha3.GitCredentials,
len(c.OPAControlPlaneConfig.GitCredentials),
)
for i, c := range c.OPAControlPlaneConfig.GitCredentials {
v2cfg3.OPAControlPlaneConfig.GitCredentials[i] = &v2alpha3.GitCredentials{
ID: c.ID,
RepoPrefix: c.RepoPrefix,
}
}
}

if c.OPAControlPlaneConfig.BundleObjectStorage != nil && c.OPAControlPlaneConfig.BundleObjectStorage.S3 != nil {
v2cfg3.OPAControlPlaneConfig.BundleObjectStorage = &v2alpha3.BundleObjectStorage{
S3: &v2alpha3.S3ObjectStorage{
Bucket: c.OPAControlPlaneConfig.BundleObjectStorage.S3.Bucket,
URL: c.OPAControlPlaneConfig.BundleObjectStorage.S3.URL,
Region: c.OPAControlPlaneConfig.BundleObjectStorage.S3.Region,
OCPConfigSecretName: c.OPAControlPlaneConfig.BundleObjectStorage.S3.OCPConfigSecretName,
},
}
}

v2cfg3.OPAControlPlaneConfig.DefaultRequirements = make(
[]v2alpha3.DefaultRequirement,
len(c.OPAControlPlaneConfig.DefaultRequirements),
)
for i, requirement := range c.OPAControlPlaneConfig.DefaultRequirements {
v2cfg3.OPAControlPlaneConfig.DefaultRequirements[i] = v2alpha3.DefaultRequirement{
Name: requirement,
RequirementType: v2alpha3.RequirementTypeUnknown,
}
}

if c.OPAControlPlaneConfig.DecisionAPIConfig != nil {
v2cfg3.OPAControlPlaneConfig.DecisionAPIConfig = &v2alpha3.DecisionAPIConfig{
ServiceURL: c.OPAControlPlaneConfig.DecisionAPIConfig.ServiceURL,
Reporting: v2alpha3.DecisionLogReporting{
MaxDelaySeconds: c.OPAControlPlaneConfig.DecisionAPIConfig.Reporting.MaxDelaySeconds,
MinDelaySeconds: c.OPAControlPlaneConfig.DecisionAPIConfig.Reporting.MinDelaySeconds,
UploadSizeLimitBytes: c.OPAControlPlaneConfig.DecisionAPIConfig.Reporting.UploadSizeLimitBytes,
},
}
}
}

if c.UserCredentialHandler != nil && c.UserCredentialHandler.S3 != nil {
v2cfg3.UserCredentialHandler = &v2alpha3.UserCredentialHandler{
S3: &v2alpha3.S3Handler{
Bucket: c.UserCredentialHandler.S3.Bucket,
URL: c.UserCredentialHandler.S3.URL,
Region: c.UserCredentialHandler.S3.Region,
AccessKeyID: c.UserCredentialHandler.S3.AccessKeyID,
SecretAccessKey: c.UserCredentialHandler.S3.SecretAccessKey,
},
}
}

return v2cfg3
}

func init() {
SchemeBuilder.Register(&ProjectConfig{})
}
37 changes: 37 additions & 0 deletions api/config/v2alpha3/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
Copyright (C) 2025 Bankdata (bankdata@bankdata.dk)

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 v2alpha3 contains API Schema definitions for the config v2alpha3 API group
// +kubebuilder:object:generate=true
// +kubebuilder:skip
// +groupName=config.bankdata.dk
package v2alpha3

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "config.bankdata.dk", Version: "v2alpha3"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
)
Loading
Loading