Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revert custom renovate config maps #388

Merged
merged 1 commit into from
Dec 18, 2024
Merged
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
169 changes: 0 additions & 169 deletions controllers/component_dependency_update_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,175 +402,6 @@ var _ = Describe("Component nudge controller", func() {
return renovatePipelinesCreated == 1 && renovateConfigsCreated == 2 && failureCount == 0
}, timeout, interval).WithTimeout(ensureTimeout).Should(BeTrue())
})

It("Test build performs nudge on success, only namespace wide renovate config provided", func() {
customConfigMapName := types.NamespacedName{Namespace: UserNamespace, Name: NamespaceWideRenovateConfigName}
customConfigString := `{"username":"namespacewideconfiguserjson"}`
customConfigMapData := map[string]string{ConfigKeyJson: customConfigString}
createCustomRenovateConfigMap(customConfigMapName, customConfigMapData)
customConfigType := "json"

createBuildPipelineRun("test-pipeline-1", UserNamespace, BaseComponent)
Eventually(func() bool {
pr := getPipelineRun("test-pipeline-1", UserNamespace)
return controllerutil.ContainsFinalizer(pr, NudgeFinalizer)
}, timeout, interval).WithTimeout(ensureTimeout).Should(BeTrue())
pr := getPipelineRun("test-pipeline-1", UserNamespace)
pr.Status.SetCondition(&apis.Condition{
Type: apis.ConditionSucceeded,
Status: "True",
LastTransitionTime: apis.VolatileTime{Inner: metav1.Time{Time: time.Now()}},
})
pr.Status.Results = []tektonapi.PipelineRunResult{
{Name: ImageDigestParamName, Value: tektonapi.ResultValue{Type: tektonapi.ParamTypeString, StringVal: "sha256:12345"}},
{Name: ImageUrl, Value: tektonapi.ResultValue{Type: tektonapi.ParamTypeString, StringVal: "quay.io.foo/bar:latest"}},
}
pr.Status.CompletionTime = &metav1.Time{Time: time.Now()}
Expect(k8sClient.Status().Update(ctx, pr)).Should(BeNil())

Eventually(func() bool {
// check that no nudgeerror event was reported
failureCount := getRenovateFailedEventCount()
// check that renovate config was created
renovateConfigsCreated := len(getRenovateConfigMapList())
// check that renovate pipeline run was created
renovatePipelinesCreated := len(getRenovatePipelineRunList())
return renovatePipelinesCreated == 1 && renovateConfigsCreated == 2 && failureCount == 0
}, timeout, interval).WithTimeout(ensureTimeout).Should(BeTrue())

renovateConfigMaps := getRenovateConfigMapList()
Expect(len(renovateConfigMaps)).Should(Equal(2))

for _, renovateConfig := range renovateConfigMaps {
if strings.HasPrefix(renovateConfig.ObjectMeta.Name, "renovate-pipeline") {
for key, val := range renovateConfig.Data {
Expect(val).Should(Equal(customConfigString))
Expect(strings.HasSuffix(key, customConfigType))
}
break
}
}
deleteConfigMap(customConfigMapName)
})

It("Test build performs nudge on success, only component renovate config provided", func() {
customConfigName := fmt.Sprintf("nudging-renovate-config-%s", Operator1)
customConfigMapName1 := types.NamespacedName{Namespace: UserNamespace, Name: customConfigName}
customConfigString := `{"username":"componentconfiguserjs"}`
customConfigMapData := map[string]string{ConfigKeyJs: customConfigString}
createCustomRenovateConfigMap(customConfigMapName1, customConfigMapData)

customConfigName = fmt.Sprintf("nudging-renovate-config-%s", Operator2)
customConfigMapName2 := types.NamespacedName{Namespace: UserNamespace, Name: customConfigName}
createCustomRenovateConfigMap(customConfigMapName2, customConfigMapData)
customConfigType := "js"

createBuildPipelineRun("test-pipeline-1", UserNamespace, BaseComponent)
Eventually(func() bool {
pr := getPipelineRun("test-pipeline-1", UserNamespace)
return controllerutil.ContainsFinalizer(pr, NudgeFinalizer)
}, timeout, interval).WithTimeout(ensureTimeout).Should(BeTrue())
pr := getPipelineRun("test-pipeline-1", UserNamespace)
pr.Status.SetCondition(&apis.Condition{
Type: apis.ConditionSucceeded,
Status: "True",
LastTransitionTime: apis.VolatileTime{Inner: metav1.Time{Time: time.Now()}},
})
pr.Status.Results = []tektonapi.PipelineRunResult{
{Name: ImageDigestParamName, Value: tektonapi.ResultValue{Type: tektonapi.ParamTypeString, StringVal: "sha256:12345"}},
{Name: ImageUrl, Value: tektonapi.ResultValue{Type: tektonapi.ParamTypeString, StringVal: "quay.io.foo/bar:latest"}},
}
pr.Status.CompletionTime = &metav1.Time{Time: time.Now()}
Expect(k8sClient.Status().Update(ctx, pr)).Should(BeNil())

Eventually(func() bool {
// check that no nudgeerror event was reported
failureCount := getRenovateFailedEventCount()
// check that renovate config was created
renovateConfigsCreated := len(getRenovateConfigMapList())
// check that renovate pipeline run was created
renovatePipelinesCreated := len(getRenovatePipelineRunList())
return renovatePipelinesCreated == 1 && renovateConfigsCreated == 2 && failureCount == 0
}, timeout, interval).WithTimeout(ensureTimeout).Should(BeTrue())

renovateConfigMaps := getRenovateConfigMapList()
Expect(len(renovateConfigMaps)).Should(Equal(2))

for _, renovateConfig := range renovateConfigMaps {
if strings.HasPrefix(renovateConfig.ObjectMeta.Name, "renovate-pipeline") {
for key, val := range renovateConfig.Data {
Expect(val).Should(Equal(customConfigString))
Expect(strings.HasSuffix(key, customConfigType))
}
break
}
}
deleteConfigMap(customConfigMapName1)
deleteConfigMap(customConfigMapName2)
})

It("Test build performs nudge on success, namespace wide and component renovate config provided", func() {
customConfigMapName := types.NamespacedName{Namespace: UserNamespace, Name: NamespaceWideRenovateConfigName}
customConfigString := `{"username":"namespacewideconfiguserjson"}`
customConfigMapData := map[string]string{ConfigKeyJson: customConfigString}
createCustomRenovateConfigMap(customConfigMapName, customConfigMapData)

customConfigName := fmt.Sprintf("nudging-renovate-config-%s", Operator1)
customConfigMapName1 := types.NamespacedName{Namespace: UserNamespace, Name: customConfigName}
customConfigString1 := `{"username":"componentconfiguserjs"}`
customConfigString2 := `{"username":"componentconfiguserjson"}`
customConfigMapData = map[string]string{ConfigKeyJs: customConfigString1, ConfigKeyJson: customConfigString2}
createCustomRenovateConfigMap(customConfigMapName1, customConfigMapData)

customConfigName = fmt.Sprintf("nudging-renovate-config-%s", Operator2)
customConfigMapName2 := types.NamespacedName{Namespace: UserNamespace, Name: customConfigName}
createCustomRenovateConfigMap(customConfigMapName2, customConfigMapData)
customConfigType := "json"

createBuildPipelineRun("test-pipeline-1", UserNamespace, BaseComponent)
Eventually(func() bool {
pr := getPipelineRun("test-pipeline-1", UserNamespace)
return controllerutil.ContainsFinalizer(pr, NudgeFinalizer)
}, timeout, interval).WithTimeout(ensureTimeout).Should(BeTrue())
pr := getPipelineRun("test-pipeline-1", UserNamespace)
pr.Status.SetCondition(&apis.Condition{
Type: apis.ConditionSucceeded,
Status: "True",
LastTransitionTime: apis.VolatileTime{Inner: metav1.Time{Time: time.Now()}},
})
pr.Status.Results = []tektonapi.PipelineRunResult{
{Name: ImageDigestParamName, Value: tektonapi.ResultValue{Type: tektonapi.ParamTypeString, StringVal: "sha256:12345"}},
{Name: ImageUrl, Value: tektonapi.ResultValue{Type: tektonapi.ParamTypeString, StringVal: "quay.io.foo/bar:latest"}},
}
pr.Status.CompletionTime = &metav1.Time{Time: time.Now()}
Expect(k8sClient.Status().Update(ctx, pr)).Should(BeNil())

Eventually(func() bool {
// check that no nudgeerror event was reported
failureCount := getRenovateFailedEventCount()
// check that renovate config was created
renovateConfigsCreated := len(getRenovateConfigMapList())
// check that renovate pipeline run was created
renovatePipelinesCreated := len(getRenovatePipelineRunList())
return renovatePipelinesCreated == 1 && renovateConfigsCreated == 2 && failureCount == 0
}, timeout, interval).WithTimeout(ensureTimeout).Should(BeTrue())

renovateConfigMaps := getRenovateConfigMapList()
Expect(len(renovateConfigMaps)).Should(Equal(2))

for _, renovateConfig := range renovateConfigMaps {
if strings.HasPrefix(renovateConfig.ObjectMeta.Name, "renovate-pipeline") {
for key, val := range renovateConfig.Data {
Expect(val).Should(Equal(customConfigString2))
Expect(strings.HasSuffix(key, customConfigType))
}
break
}
}
deleteConfigMap(customConfigMapName)
deleteConfigMap(customConfigMapName1)
deleteConfigMap(customConfigMapName2)
})
})

Context("Test nudge failure handling", func() {
Expand Down
82 changes: 15 additions & 67 deletions controllers/renovate_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,14 @@ import (
)

const (
RenovateImageEnvName = "RENOVATE_IMAGE"
DefaultRenovateImageUrl = "quay.io/konflux-ci/mintmaker-renovate-image:cdbc220"
DefaultRenovateUser = "red-hat-konflux"
CaConfigMapLabel = "config.openshift.io/inject-trusted-cabundle"
CaConfigMapKey = "ca-bundle.crt"
CaFilePath = "tls-ca-bundle.pem"
CaMountPath = "/etc/pki/ca-trust/extracted/pem"
CaVolumeMountName = "trusted-ca"
NamespaceWideRenovateConfigName = "namespace-wide-nudging-renovate-config"
ComponentRenovateConfigNamePrefix = "nudging-renovate-config-"
ConfigKeyJson = "config.json"
ConfigKeyJs = "config.js"
RenovateImageEnvName = "RENOVATE_IMAGE"
DefaultRenovateImageUrl = "quay.io/konflux-ci/mintmaker-renovate-image:cdbc220"
DefaultRenovateUser = "red-hat-konflux"
CaConfigMapLabel = "config.openshift.io/inject-trusted-cabundle"
CaConfigMapKey = "ca-bundle.crt"
CaFilePath = "tls-ca-bundle.pem"
CaMountPath = "/etc/pki/ca-trust/extracted/pem"
CaVolumeMountName = "trusted-ca"
)

type renovateRepository struct {
Expand Down Expand Up @@ -379,60 +375,26 @@ func (u ComponentDependenciesUpdater) CreateRenovaterPipeline(ctx context.Contex
secretTokens := map[string]string{}
configmaps := map[string]string{}
renovateCmds := []string{}
globalConfigString := ""
globalConfigType := ""

allUserConfigMaps := &corev1.ConfigMapList{}
if err := u.Client.List(ctx, allUserConfigMaps, client.InNamespace(namespace)); err != nil {
return fmt.Errorf("failed to list config maps in %s namespace: %w", namespace, err)
}
for _, userConfigMap := range allUserConfigMaps.Items {
if userConfigMap.Name == NamespaceWideRenovateConfigName {
globalConfigString, globalConfigType = getConfigAndTypeFromConfigMap(userConfigMap)
break
}
}

for _, target := range targets {
randomStr1 := RandomString(5)
randomStr2 := RandomString(10)
randomStr3 := RandomString(10)
secretTokens[randomStr2] = target.Token
secretTokens[randomStr3] = target.ImageRepositoryPassword
componentConfigName := fmt.Sprintf("%s%s", ComponentRenovateConfigNamePrefix, target.ComponentName)
componentConfigString := ""
componentConfigType := ""
configString := ""
configType := "json"

for _, userConfigMap := range allUserConfigMaps.Items {
if userConfigMap.Name == componentConfigName {
componentConfigString, componentConfigType = getConfigAndTypeFromConfigMap(userConfigMap)
break
}
renovateConfig, err := GenerateRenovateConfigForNudge(target, buildResult)
if err != nil {
return err
}

if componentConfigString != "" {
configString = componentConfigString
configType = componentConfigType
log.Info("will use custom renovate config for component", "name", componentConfigName, "type", configType)
} else if globalConfigString != "" {
configString = globalConfigString
configType = globalConfigType
log.Info("will use custom global renovate config", "name", NamespaceWideRenovateConfigName, "type", configType)
} else {
log.Info("will generate renovate config, no custom ones are present")
renovateConfig, err := GenerateRenovateConfigForNudge(target, buildResult)
if err != nil {
return err
}

config, err := json.Marshal(renovateConfig)
if err != nil {
return err
}
configString = string(config)
config, err := json.Marshal(renovateConfig)
if err != nil {
return err
}
configString = string(config)

log.Info(fmt.Sprintf("Creating renovate config map entry for %s component with length %d and value %s", target.ComponentName, len(configString), configString))

Expand Down Expand Up @@ -611,17 +573,3 @@ func (u ComponentDependenciesUpdater) CreateRenovaterPipeline(ctx context.Contex

return nil
}

func getConfigAndTypeFromConfigMap(configMap corev1.ConfigMap) (string, string) {
config, exists := configMap.Data[ConfigKeyJson]
if exists && len(config) > 0 {
return config, "json"
}

config, exists = configMap.Data[ConfigKeyJs]
if exists && len(config) > 0 {
return config, "js"
}

return "", ""
}
27 changes: 0 additions & 27 deletions controllers/suite_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -592,33 +592,6 @@ func createCAConfigMap(configMapKey types.NamespacedName) {
}
}

func createCustomRenovateConfigMap(configMapKey types.NamespacedName, configMapData map[string]string) {
caConfigMap := corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{Name: configMapKey.Name, Namespace: configMapKey.Namespace},
Data: configMapData,
}

if err := k8sClient.Create(ctx, &caConfigMap); err != nil && !k8sErrors.IsAlreadyExists(err) {
Fail(err.Error())
}
}

func deleteConfigMap(configMapKey types.NamespacedName) {
configMap := corev1.ConfigMap{}
if err := k8sClient.Get(ctx, configMapKey, &configMap); err != nil {
if k8sErrors.IsNotFound(err) {
return
}
Fail(err.Error())
}
if err := k8sClient.Delete(ctx, &configMap); err != nil && !k8sErrors.IsNotFound(err) {
Fail(err.Error())
}
Eventually(func() bool {
return k8sErrors.IsNotFound(k8sClient.Get(ctx, configMapKey, &configMap))
}, timeout, interval).Should(BeTrue())
}

func waitServiceAccount(serviceAccountKey types.NamespacedName) corev1.ServiceAccount {
serviceAccount := corev1.ServiceAccount{}
Eventually(func() bool {
Expand Down
Loading