-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Webhook injection no kubelet (#1573)
This pull request includes several changes to enhance the debugging setup, improve environment variable handling, and refactor code for better readability and maintainability. The most important changes include updates to the debugging configuration, injection of environment variables, and refactoring of workload handling. ### Debugging Enhancements: * [`.vscode/launch.json`](diffhunk://#diff-bd5430ee7c51dc892a67b3f2829d1f5b6d223f0fd48b82322cfd45baf9f5e945L20-R23): Added environment variables for local mutating webhook certificate directory to facilitate local debugging. * [`CONTRIBUTING.md`](diffhunk://#diff-eca12c0a30e25b4b46522ebf89465a03ba72a03f540796c979137931d8f92055R170-R202): Added detailed instructions for debugging the Instrumentor when the Mutating Webhook is enabled. ### Environment Variable Injection: * [`instrumentor/controllers/instrumentationdevice/pods_webhook.go`](diffhunk://#diff-09f9653d9c6c1a8bb7d52e7f3bf0060e0176369df0ee04d04bfb6b4d620794ddL10-L21): Introduced constants for ODIGOS environment variables and added a function to inject these variables into all containers. [[1]](diffhunk://#diff-09f9653d9c6c1a8bb7d52e7f3bf0060e0176369df0ee04d04bfb6b4d620794ddL10-L21) [[2]](diffhunk://#diff-09f9653d9c6c1a8bb7d52e7f3bf0060e0176369df0ee04d04bfb6b4d620794ddL31-R89) * [`instrumentor/main.go`](diffhunk://#diff-e36937e3510a3c05ef5f17e89c712712f4a500188cfc4818fba7e5015ebe47b2L101-R102): Added logic to check for a local webhook certificate directory and configure the WebhookServer accordingly for local development. [[1]](diffhunk://#diff-e36937e3510a3c05ef5f17e89c712712f4a500188cfc4818fba7e5015ebe47b2L101-R102) [[2]](diffhunk://#diff-e36937e3510a3c05ef5f17e89c712712f4a500188cfc4818fba7e5015ebe47b2R177-R190) ### Refactoring: * [`k8sutils/pkg/workload/ownerreference.go`](diffhunk://#diff-183ad6413c2a5e4a1aad9e9566e87fc06f88ed51afe6c6fffcb521d9f74ee556L4-R47): Refactored workload handling functions to separate concerns and improve readability. * [`opampserver/pkg/server/handlers.go`](diffhunk://#diff-944e905a1aea43bd5f8a4c5ad17b404e63ea772321096a15829fb2951723a8d8L14-R43): Refactored the `OnNewConnection` method to extract and handle agent attributes more efficiently and added helper functions for resolving Kubernetes attributes. [[1]](diffhunk://#diff-944e905a1aea43bd5f8a4c5ad17b404e63ea772321096a15829fb2951723a8d8L14-R43) [[2]](diffhunk://#diff-944e905a1aea43bd5f8a4c5ad17b404e63ea772321096a15829fb2951723a8d8L56-R79) [[3]](diffhunk://#diff-944e905a1aea43bd5f8a4c5ad17b404e63ea772321096a15829fb2951723a8d8L86-R91) [[4]](diffhunk://#diff-944e905a1aea43bd5f8a4c5ad17b404e63ea772321096a15829fb2951723a8d8L99-R104) [[5]](diffhunk://#diff-944e905a1aea43bd5f8a4c5ad17b404e63ea772321096a15829fb2951723a8d8R199-R263) ### Minor Imports Adjustments: * [`instrumentor/main.go`](diffhunk://#diff-e36937e3510a3c05ef5f17e89c712712f4a500188cfc4818fba7e5015ebe47b2R36): Added missing import for `webhook` package. * [`opampserver/pkg/server/handlers.go`](diffhunk://#diff-944e905a1aea43bd5f8a4c5ad17b404e63ea772321096a15829fb2951723a8d8L14-R43): Aliased the `deviceid` import for consistency. These changes collectively improve the development experience and code maintainability. --------- Co-authored-by: Tamir David <[email protected]>
- Loading branch information
1 parent
5c72fb0
commit 5ffff7e
Showing
8 changed files
with
249 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,5 @@ go.work.sum | |
cli/odigos | ||
.venv | ||
**/__pycache__/ | ||
**/*.pyc | ||
**/*.pyc | ||
serving-certs/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,43 @@ | ||
package workload | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"strings" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// GetWorkloadFromOwnerReference retrieves both the workload name and workload kind | ||
// from the provided owner reference. | ||
func GetWorkloadFromOwnerReference(ownerReference metav1.OwnerReference) (workloadName string, workloadKind WorkloadKind, err error) { | ||
ownerName := ownerReference.Name | ||
ownerKind := ownerReference.Kind | ||
|
||
return GetWorkloadNameAndKind(ownerReference.Name, ownerReference.Kind) | ||
} | ||
|
||
func GetWorkloadNameAndKind(ownerName, ownerKind string) (string, WorkloadKind, error) { | ||
if ownerKind == "ReplicaSet" { | ||
// ReplicaSet name is in the format <deployment-name>-<random-string> | ||
hyphenIndex := strings.LastIndex(ownerName, "-") | ||
if hyphenIndex == -1 { | ||
// It is possible for a user to define a bare ReplicaSet without a deployment, currently not supporting this | ||
err = errors.New("replicaset name does not contain a hyphen") | ||
return | ||
} | ||
// Extract deployment name from ReplicaSet name | ||
workloadName = ownerName[:hyphenIndex] | ||
workloadKind = WorkloadKindDeployment | ||
return | ||
return extractDeploymentInfo(ownerName) | ||
} | ||
return handleNonReplicaSet(ownerName, ownerKind) | ||
} | ||
|
||
// extractDeploymentInfo extracts deployment information from a ReplicaSet name | ||
func extractDeploymentInfo(replicaSetName string) (string, WorkloadKind, error) { | ||
hyphenIndex := strings.LastIndex(replicaSetName, "-") | ||
if hyphenIndex == -1 { | ||
return "", "", fmt.Errorf("replicaset name '%s' does not contain a hyphen", replicaSetName) | ||
} | ||
|
||
workloadKind = WorkloadKindFromString(ownerKind) | ||
deploymentName := replicaSetName[:hyphenIndex] | ||
return deploymentName, WorkloadKindDeployment, nil | ||
} | ||
|
||
// handleNonReplicaSet processes non-ReplicaSet workload types | ||
func handleNonReplicaSet(ownerName, ownerKind string) (string, WorkloadKind, error) { | ||
workloadKind := WorkloadKindFromString(ownerKind) | ||
if workloadKind == "" { | ||
err = ErrKindNotSupported | ||
return | ||
return "", "", ErrKindNotSupported | ||
} | ||
workloadName = ownerName | ||
|
||
err = nil | ||
return | ||
return ownerName, workloadKind, nil | ||
} |
Oops, something went wrong.