Skip to content

Conversation

@manusa
Copy link
Member

@manusa manusa commented Jun 17, 2025

Prevents consumers of the kubernetes package the usage of public methods on a non-derived config instance.

/cc @ardaguclu

Prevents consumers of the kubernetes package the usage of
public methods on a non-derived config instance.
@manusa manusa added this to the 0.1.0 milestone Jun 17, 2025 — with automated-tasks
IsOpenShift(ctx context.Context) bool
}

type DerivedKubernetes interface {
Copy link
Member

Choose a reason for hiding this comment

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

This interface is too rigid to be used to implement different DerivedKubernetes objects. In my opinion, having a struct is better, probably after renaming the Kubernetes (which hides the package names) to KubernetesManager.

type CloseWatchKubeConfig func() error

type Kubernetes struct {
type Kubernetes interface {
Copy link
Member

Choose a reason for hiding this comment

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

Same, I don't think we need this for now

ResourcesDelete(ctx context.Context, gvk *schema.GroupVersionKind, namespace, name string) error
}

type kubernetes struct {
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 recommend renaming it to KubernetesManager. I don't think, exporting the fields in here hurts us. However, in my opinion, maybe we can get rid of some of them (e.g. I bet we don't need parameterCodec by using an upstream functionality.).

return derived
}

func (k *kubernetes) CacheInvalidate() {
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need invalidating the cache?. Doesn't MCP server interact with the same cluster throughout its lifetime?. Stdio would require this. But maybe when stdio is used, we fully use a different path.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is currently used for testing purposes only.
In this case, the cache becomes stale because the metrics-api is made available after an initial check.

As stated, this isn't used as of now in production code, but I assume that similar circumstances might happen in a real cluster (cluster is the same, available resources might change).

Copy link
Member

Choose a reason for hiding this comment

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

DiscoveryClient has etag mechanism that compares the cached hash values against the API Server each time. If it detects any change in etags, it internally invalidates the cache.

Copy link
Member Author

@manusa manusa Jun 17, 2025

Choose a reason for hiding this comment

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

We should check that together, the test doesn't validate that behavior (I think). (I'll add a TODO)

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, this invalidation mechanism requires to have an actual API server. So I wouldn't be surprised if unit tests fails due to this. Would it be an issue to add this invalidation in unit test?.

Copy link
Member

Choose a reason for hiding this comment

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

kubernetes/enhancements#3352 in case you are interested in

Copy link
Member Author

Choose a reason for hiding this comment

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

The test using this is here: https://github.com/manusa/kubernetes-mcp-server/blob/54d564a54e38febc63c56c60b9ccb76501adf55f/pkg/mcp/pods_top_test.go#L10

There's a fake API server behind which does reply. Only one request is performed.
I'll set the TODO and we can check later

@manusa manusa requested a review from ardaguclu June 17, 2025 13:33
@manusa
Copy link
Member Author

manusa commented Jun 17, 2025

@ardaguclu, please check if the subsequent commit aligns with your expectations

@manusa manusa force-pushed the refactor/force-derived branch from d67ac47 to 56576c1 Compare June 17, 2025 13:36
@manusa manusa force-pushed the refactor/force-derived branch from 56576c1 to a5cd799 Compare June 17, 2025 13:40
@ardaguclu
Copy link
Member

This looks good to me
/lgtm

@manusa manusa merged commit f138b06 into main Jun 18, 2025
5 checks passed
@manusa manusa deleted the refactor/force-derived branch June 18, 2025 04:46
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