Skip to content

Conversation

@unshade
Copy link
Member

@unshade unshade commented Oct 6, 2025

This PR allows users to add a CIDR whitelist to access kubernetes apiserver

@unshade unshade requested review from Copilot and yyewolf October 6, 2025 12:56
@unshade unshade self-assigned this Oct 6, 2025
@sonarqubecloud
Copy link

sonarqubecloud bot commented Oct 6, 2025

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds IP CIDR filtering functionality to allow users to whitelist specific CIDR blocks or IPs for accessing the Kubernetes API server in the Infomaniak KaaS (Kubernetes as a Service) resource.

  • Adds acl_rules field to the apiserver configuration for specifying allowed CIDR blocks/IPs
  • Implements API methods for patching and retrieving IP filters
  • Updates both resource and data source schemas to support the new filtering capability

Reviewed Changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
internal/services/kaas/kaas_resource.go Adds acl_rules field to ApiserverModel and implements IP filtering in Create/Update/Read operations
internal/services/kaas/kaas_data_source.go Adds acl_rules field to data source schema and implements IP filter retrieval
internal/apis/kaas/spec.go Defines API interface methods for IP filter operations
internal/apis/kaas/mock/client.go Implements mock client methods for IP filter operations
internal/apis/kaas/implementation/endpoints.go Adds IP filter endpoint constant
internal/apis/kaas/implementation/client.go Implements actual API client methods for IP filter operations
examples/kaas-ip-filter/variables.tf Defines variables for IP filter example configuration
examples/kaas-ip-filter/main.tf Shows usage example of IP filtering in Terraform configuration
docs/resources/kaas.md Documents the new acl_rules configuration option

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +372 to +388
if !data.Apiserver.AllowRequestsFromCIDR.IsNull() {
allowedCidrs := make([]string, 0, len(data.Apiserver.AllowRequestsFromCIDR.Elements()))
resp.Diagnostics.Append(data.Apiserver.AllowRequestsFromCIDR.ElementsAs(ctx, &allowedCidrs, true)...)
ok, err := r.client.Kaas.PatchIPFilters(allowedCidrs, input.Project.PublicCloudId, input.Project.ProjectId, kaasId)
if !ok || err != nil {
var errMsg string
if err != nil {
errMsg = err.Error()
} else {
errMsg = "PatchIPFilters returned false but no error was provided"
}
resp.Diagnostics.AddError(
"Error when applying network filtering",
errMsg,
)
}
}
Copy link

Copilot AI Oct 6, 2025

Choose a reason for hiding this comment

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

The IP filter patching logic is duplicated in both Create and Update methods. Consider extracting this into a separate method to reduce code duplication.

Copilot uses AI. Check for mistakes.
state.fillApiserverState(ctx, apiserverParams)
}

filteredIps, err := r.client.Kaas.GetIPFilters(int(state.PublicCloudId.ValueInt64()), int(state.PublicCloudProjectId.ValueInt64()), kaasObject.Id)
Copy link

Copilot AI Oct 6, 2025

Choose a reason for hiding this comment

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

The error handling for GetIPFilters doesn't return early on error, which means the function continues executing and may set incomplete state. Consider adding a return statement after the error diagnostic.

Copilot uses AI. Check for mistakes.
SetPathParam("public_cloud_project_id", fmt.Sprint(projectId)).
SetPathParam("kaas_id", fmt.Sprint(kaasId)).
SetBody(body).
SetDebug(true).
Copy link

Copilot AI Oct 6, 2025

Choose a reason for hiding this comment

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

Debug mode should not be hardcoded to true in production code. This should be configurable or removed for production builds.

Copilot uses AI. Check for mistakes.
SetPathParam("public_cloud_id", fmt.Sprint(publicCloudId)).
SetPathParam("public_cloud_project_id", fmt.Sprint(projectId)).
SetPathParam("kaas_id", fmt.Sprint(kaasId)).
SetDebug(true).
Copy link

Copilot AI Oct 6, 2025

Choose a reason for hiding this comment

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

Debug mode should not be hardcoded to true in production code. This should be configurable or removed for production builds.

Copilot uses AI. Check for mistakes.
@yyewolf yyewolf added enhancement New feature or request go Pull requests that update go code awaiting api changes This issue is awaiting changes from the API pre-approved lgtm labels Oct 8, 2025
@unshade unshade changed the title feat: ip cidr filtering feat(kaas): ip cidr filtering Oct 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting api changes This issue is awaiting changes from the API enhancement New feature or request go Pull requests that update go code lgtm pre-approved

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants