Skip to content

Comments

feat: implement config cache-proxy command#54

Open
tisutisu wants to merge 3 commits intokonflux-ci:mainfrom
tisutisu:implement-init-cmd
Open

feat: implement config cache-proxy command#54
tisutisu wants to merge 3 commits intokonflux-ci:mainfrom
tisutisu:implement-init-cmd

Conversation

@tisutisu
Copy link

@tisutisu tisutisu commented Feb 9, 2026

This PR implements the konflux-build-cli config cache-proxy --enable <true/false> cmd, to be used during build-definitions init task replacement using golang CLI.

@tisutisu tisutisu requested a review from a team as a code owner February 9, 2026 05:52
@snyk-io
Copy link

snyk-io bot commented Feb 9, 2026

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues
Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

Comment on lines 89 to 97
l.Logger.Infof("cluster-config config map data: %v", cm.Data)
allowCache = cm.Data["allow-cache-proxy"]
if allowCache == "true" {
httpProxy = cm.Data["http-proxy"]
noProxy = cm.Data["no-proxy"]
} else {
httpProxy = ""
noProxy = ""
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this piece of code in else branch?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise setting default*Proxy has no effect. They are reassigned by reading http-proxy and no-proxy from cm.Data.

Copy link
Author

@tisutisu tisutisu Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have felt this same while writing the logic, but kept the logic same as per the current bash implementation here

Copy link
Contributor

@tkdchen tkdchen Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The below if-else is relative to the link you mentioned.

https://github.com/konflux-ci/build-definitions/blob/a91adc4f10bf5dc684fe32b373fd718253945cd4/task/init/0.3/init.yaml#L44-L61 is relative to the commented lines I think. Code from line 44 to 61 has this logic:

  • if configmap is present, http_proxy and no_proxy are assigned according to the config data.
  • if configmap is not present, use the defaults.

Copy link
Author

@tisutisu tisutisu Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got your point now, thanks for catching it.
Addressed it on the latest commit 787fee7

Copy link
Contributor

@tkdchen tkdchen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can also wrap kubectl (it's included in task-runner) command instead of calling kubenetes APIs, which is similar with other nested commands. Invoking kubectl could also help us having less effort on maintaining dependencies updates.

@tisutisu
Copy link
Author

Maybe we can also wrap kubectl (it's included in task-runner) command instead of calling kubenetes APIs, which is similar with other nested commands. Invoking kubectl could also help us having less effort on maintaining dependencies updates.

@tkdchen even if we use cli, for reading/unmarshalling of kubectl cmd outputs, we need to depend on the kubernetes pkgs like k8s.io/api/core/v1, otherwise we have to duplicate code in our own implementation for reading ConfigMaps, not sure if we should go with wrapper around kubectl. WDYT?

Copy link
Member

@mmorhun mmorhun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be out of scope of this PR, but it anyway blocks it.
The main problem is that we accessing k8s cluster directly from within CLI making it tightly bound and dependent on k8s environment, making it impossible to run without a cluster, say locally or in another than Tekton CI. (Obviously, there are workarounds, but we need a proper solution).

My suggestion is to create a abstraction layer, say ConfigReader that would detect the environment (easiest is to use env var) and then read k8s resources if run within k8s cluster or access config in different source (say ini or env file) otherwise.

@tisutisu tisutisu force-pushed the implement-init-cmd branch 2 times, most recently from eddf14f to 8d1f0fd Compare February 16, 2026 13:35
Copy link
Member

@mmorhun mmorhun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need ConfigReader interface with a factory (NewConfigReader) that constructs required implementation (K8sConfigReader or EnvFileConfigReader) based on an env var (if not set, k8s is the default). Then config command(s) can use it.

@tisutisu tisutisu force-pushed the implement-init-cmd branch 3 times, most recently from fa990a8 to d53204e Compare February 17, 2026 06:36
Usage: "Whether to enable cache proxy or not. Required.",
Required: true,
},
"config-file": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the config contains global platform setting and not only proxy config, I think that should be configured on the ConfigReader level via an env var.

Copy link
Author

@tisutisu tisutisu Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the code to read from a platform config file named PLATFORM_CONFIG_FILE from the env.

os.Getenv("PLATFORM_CONFIG_FILE")

PTAL again.

Comment on lines 14 to 15
configMapNamespace = "cluster-config"
configMapName = "konflux-info"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are properties of k8sConfigReader

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

Comment on lines 16 to 17
defaultHttpProxy = "squid.caching.svc.cluster.local:3128"
defaultNoProxy = "brew.registry.redhat.io,docker.io,gcr.io,ghcr.io,images.paas.redhat.com,mirror.gcr.io,nvcr.io,quay.io,registry-proxy.engineering.redhat.com,registry.access.redhat.com,registry.ci.openshift.org,registry.fedoraproject.org,registry.redhat.io,registry.stage.redhat.io,vault.habana.ai"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to not to have such defaults here, but have them in the Tekton task env.

if err != nil {
return err
}
c.Configs.ConfigReader = &config.K8sConfigMapReader{Name: configMapName, Namespace: configMapNamespace, Clientset: clientset}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have something like:

ConfigReader = NewConfigReader()

in the command constructor.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

c.logParams()

l.Logger.Debug("Reading config-map data")
cmData, err := c.Configs.ConfigReader.ReadConfigData()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: instead of cmData, it's better to have configData or something like that (to not to have hard k8s connection)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed it to cacheProxyConfig now. agnostic of k8s connection.

}
}

// Apply ENABLE_CACHE_PROXY check (from task param) ONLY if cluster allows it
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better say if backend allows it and say, for example, k8s cluster.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated.


// ReadConfigData reads the YAML file, unmarshals it and returns the config data from the configmap.
func (y *YAMLFileReader) ReadConfigData() (map[string]string, error) {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: Extra empty line

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated.

return nil, fmt.Errorf("failed to read file %s: %w", y.FilePath, err)
}

configMap := corev1.ConfigMap{}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's assume that the command runs in non k8s environment. How comfortable it is to deal with k8s config map in such an environment (e.g. GitHub action?) to provide the config?

Copy link
Author

@tisutisu tisutisu Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now reading from an ini file.

Comment on lines +98 to +101
if err != nil {
return nil, err
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a leftover

return cacheProxy, nil
}

func (c *CacheProxy) initializeConfigs() error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure that we need a separate function for creating an instance of ConfigReader

Comment on lines +129 to +130
l.Logger.Warnf("Error while reading config map: %s", err.Error())
// ConfigMap missing, use defaults
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The command should know nothing about ConfigMaps

if err != nil {
return nil, err
}
return &K8sConfigMapReader{Name: "cluster-config", Namespace: "konflux-info", Clientset: clientset}, nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should those be configurable via env vars too with the above defaults?

"k8s.io/client-go/kubernetes"
)

type CacheProxyConfig struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are reading config from "konflux-info", should the struct have a generic name?

@@ -0,0 +1,5 @@
[cache-proxy]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to create this file in tempdir from tests?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants