Skip to content

Commit

Permalink
Remove CRA migrations (#18628)
Browse files Browse the repository at this point in the history
* Remove migrations

* Remove golangci lint
  • Loading branch information
VOID404 authored Apr 2, 2024
1 parent aa7366d commit b8ff9e3
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 417 deletions.
24 changes: 0 additions & 24 deletions .github/workflows/lint-compass-runtime-agent.yml

This file was deleted.

66 changes: 0 additions & 66 deletions components/compass-runtime-agent/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"context"
"encoding/json"
"github.com/google/uuid"
"github.com/kyma-incubator/compass/components/director/pkg/correlation"
"github.com/kyma-incubator/compass/components/director/pkg/str"
Expand All @@ -21,7 +20,6 @@ import (
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/vrischmann/envconfig"
"k8s.io/apimachinery/pkg/types"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/manager"
Expand All @@ -42,7 +40,6 @@ func main() {
cfg, err := config.GetConfig()
exitOnError(err, "Failed to set up client config")

log.Info("Migrating certificate if needed")
k8sResourceClientSets, err := k8sResourceClients(cfg)
exitOnError(err, "Failed to initialize K8s resource clients")

Expand All @@ -51,24 +48,11 @@ func main() {
}

caCertSecret := parseNamespacedName(options.CaCertificatesSecret)
caCertSecretToMigrate := parseNamespacedName(options.CaCertSecretToMigrate)

secretsRepository := secrets.NewRepository(secretsManagerConstructor)

err = migrateSecret(secretsRepository, caCertSecretToMigrate, caCertSecret, options.CaCertSecretKeysToMigrate)
exitOnError(err, "Failed to migrate ")

log.Info("Migrating credentials if needed")
clusterCertSecret := parseNamespacedName(options.ClusterCertificatesSecret)
agentConfigSecret := parseNamespacedName(options.AgentConfigurationSecret)
oldClusterCertSecret := parseNamespacedName(options.ClusterCertificatesSecretToMigrate)
oldAgentConfigSecret := parseNamespacedName(options.AgentConfigurationSecretToMigrate)

err = migrateSecretAllKeys(secretsRepository, oldClusterCertSecret, clusterCertSecret)
exitOnError(err, "Failed to migrate ")

err = migrateSecretAllKeys(secretsRepository, oldAgentConfigSecret, agentConfigSecret)
exitOnError(err, "Failed to migrate ")

log.Info("Setting up manager")
mgr, err := manager.New(cfg, manager.Options{SyncPeriod: &options.ControllerSyncPeriod})
Expand Down Expand Up @@ -132,56 +116,6 @@ func main() {
exitOnError(err, "Failed to run the manager")
}

func migrateSecretAllKeys(secretRepo secrets.Repository, sourceSecret, targetSecret types.NamespacedName) error {

includeAllKeysFunc := func(k string) bool {
return true
}

migrator := certificates.NewMigrator(secretRepo, includeAllKeysFunc)
return migrator.Do(sourceSecret, targetSecret)
}

func migrateSecret(secretRepo secrets.Repository, sourceSecret, targetSecret types.NamespacedName, keysToInclude string) error {
unmarshallKeysList := func(keys string) (keysArray []string, err error) {
err = json.Unmarshal([]byte(keys), &keysArray)

return keysArray, err
}

keys, err := unmarshallKeysList(keysToInclude)
if err != nil {
log.Errorf("Failed to read secret keys to be migrated")
return err
}

migrator := getMigrator(secretRepo, keys)

return migrator.Do(sourceSecret, targetSecret)
}

func getMigrator(secretRepo secrets.Repository, keysToInclude []string) certificates.Migrator {
getIncludeSourceKeyFunc := func() certificates.IncludeKeyFunc {
if len(keysToInclude) == 0 {
return func(string) bool {
return true
}
}

return func(key string) bool {
for _, k := range keysToInclude {
if k == key {
return true
}
}

return false
}
}

return certificates.NewMigrator(secretRepo, getIncludeSourceKeyFunc())
}

func createSynchronisationService(k8sResourceClients *k8sResourceClientSets, options Config) (kyma.Service, error) {

var syncService kyma.Service
Expand Down
43 changes: 18 additions & 25 deletions components/compass-runtime-agent/cmd/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,21 @@ const (
)

type Config struct {
AgentConfigurationSecret string `envconfig:"default=kyma-system/compass-agent-configuration"`
ControllerSyncPeriod time.Duration `envconfig:"default=20s"`
MinimalCompassSyncTime time.Duration `envconfig:"default=10s"`
CertValidityRenewalThreshold float64 `envconfig:"default=0.3"`
ClusterCertificatesSecret string `envconfig:"default=kyma-system/cluster-client-certificates"`
CaCertificatesSecret string `envconfig:"default=istio-system/ca-certificates"`
SkipCompassTLSVerify bool `envconfig:"default=false"`
GatewayPort int `envconfig:"default=8080"`
SkipAppsTLSVerify bool `envconfig:"default=false"`
CentralGatewayServiceUrl string `envconfig:"default=http://central-application-gateway.kyma-system.svc.cluster.local:8082"`
QueryLogging bool `envconfig:"default=false"`
MetricsLoggingTimeInterval time.Duration `envconfig:"default=30m"`
HealthPort string `envconfig:"default=8090"`
IntegrationNamespace string `envconfig:"default=kyma-system"`
CaCertSecretToMigrate string `envconfig:"optional"`
CaCertSecretKeysToMigrate string `envconfig:"default='cacert'"`
ClusterCertificatesSecretToMigrate string `envconfig:"optional"`
AgentConfigurationSecretToMigrate string `envconfig:"optional"`
Runtime director.RuntimeURLsConfig
AgentConfigurationSecret string `envconfig:"default=kyma-system/compass-agent-configuration"`
ControllerSyncPeriod time.Duration `envconfig:"default=20s"`
MinimalCompassSyncTime time.Duration `envconfig:"default=10s"`
CertValidityRenewalThreshold float64 `envconfig:"default=0.3"`
ClusterCertificatesSecret string `envconfig:"default=kyma-system/cluster-client-certificates"`
CaCertificatesSecret string `envconfig:"default=istio-system/ca-certificates"`
SkipCompassTLSVerify bool `envconfig:"default=false"`
GatewayPort int `envconfig:"default=8080"`
SkipAppsTLSVerify bool `envconfig:"default=false"`
CentralGatewayServiceUrl string `envconfig:"default=http://central-application-gateway.kyma-system.svc.cluster.local:8082"`
QueryLogging bool `envconfig:"default=false"`
MetricsLoggingTimeInterval time.Duration `envconfig:"default=30m"`
HealthPort string `envconfig:"default=8090"`
IntegrationNamespace string `envconfig:"default=kyma-system"`
Runtime director.RuntimeURLsConfig
}

func (o *Config) String() string {
Expand All @@ -44,19 +40,16 @@ func (o *Config) String() string {
"SkipAppTLSVerify=%v, "+
"QueryLogging=%v, MetricsLoggingTimeInterval=%s, "+
"RuntimeEventsURL=%s, RuntimeConsoleURL=%s, "+
"HealthPort=%s, IntegrationNamespace=%s, CaCertSecretToMigrate=%s, caCertificateSecretKeysToMigrate=%s, "+
"ClusterCertificatesSecretToMigrate=%s, AgentConfigurationSecretToMigrate=%s, "+
"CentralGatewayServiceUrl=%v",
"HealthPort=%s, IntegrationNamespace=%s, CentralGatewayServiceUrl=%v",
o.AgentConfigurationSecret,
o.ControllerSyncPeriod.String(), o.MinimalCompassSyncTime.String(),
o.CertValidityRenewalThreshold, o.ClusterCertificatesSecret, o.CaCertificatesSecret,
o.SkipCompassTLSVerify, o.GatewayPort,
o.SkipAppsTLSVerify,
o.QueryLogging, o.MetricsLoggingTimeInterval,
o.Runtime.EventsURL, o.Runtime.ConsoleURL,
o.HealthPort, o.IntegrationNamespace, o.CaCertSecretToMigrate, o.CaCertSecretKeysToMigrate,
o.ClusterCertificatesSecretToMigrate, o.AgentConfigurationSecretToMigrate,
o.CentralGatewayServiceUrl)
o.HealthPort, o.IntegrationNamespace, o.CentralGatewayServiceUrl,
)
}

func parseNamespacedName(value string) types.NamespacedName {
Expand Down
98 changes: 0 additions & 98 deletions components/compass-runtime-agent/internal/certificates/migrator.go

This file was deleted.

Loading

0 comments on commit b8ff9e3

Please sign in to comment.