-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Using secret to attach identity to pod for observability publis…
…her (#607) <!-- Thanks for sending a pull request! Here are some tips for you: 1. Run unit tests and ensure that they are passing 2. If your change introduces any API changes, make sure to update the e2e tests 3. Make sure documentation is updated for your PR! --> # Description Since we are trying to move away from cloud-specific feature, hence as first step in observability publisher is to use secret for propagate identity instead of using existing workload identity way # Modifications Add `GOOGLE_APPLICATION_CREDENTIALS` for propagate google identity to pod # Tests <!-- Besides the existing / updated automated tests, what specific scenarios should be tested? Consider the backward compatibility of the changes, whether corner cases are covered, etc. Please describe the tests and check the ones that have been completed. Eg: - [x] Deploying new and existing standard models - [ ] Deploying PyFunc models --> # Checklist - [ ] Added PR label - [ ] Added unit test, integration, and/or e2e tests - [ ] Tested locally - [ ] Updated documentation - [ ] Update Swagger spec if the PR introduce API changes - [ ] Regenerated Golang and Python client if the PR introduces API changes # Release Notes <!-- Does this PR introduce a user-facing change? If no, just write "NONE" in the release-note block below. If yes, a release note is required. Enter your extended release note in the block below. If the PR requires additional action from users switching to the new release, include the string "action required". For more information about release notes, see kubernetes' guide here: http://git.k8s.io/community/contributors/guide/release-notes.md --> ```release-note ```
- Loading branch information
1 parent
7caf48a
commit 596b887
Showing
5 changed files
with
569 additions
and
70 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
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package deployment | ||
|
||
import ( | ||
"fmt" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
func enrichIdentityToPod(podSpec corev1.PodSpec, secretName string, containerNames []string) corev1.PodSpec { | ||
secretVolume := createVolumeFromSecret(secretName) | ||
updatedPodSpec := podSpec.DeepCopy() | ||
|
||
containerExist := false | ||
containerNameLookup := make(map[string]bool) | ||
for _, containerName := range containerNames { | ||
containerNameLookup[containerName] = true | ||
} | ||
|
||
for idx, containerSpec := range updatedPodSpec.Containers { | ||
if val := containerNameLookup[containerSpec.Name]; !val { | ||
continue | ||
} | ||
|
||
containerExist = true | ||
mountPath := fmt.Sprintf("/iam/%s", secretName) | ||
volumeMount := corev1.VolumeMount{ | ||
Name: secretVolume.Name, | ||
MountPath: mountPath, | ||
ReadOnly: true, | ||
} | ||
containerSpec.VolumeMounts = append(containerSpec.VolumeMounts, volumeMount) | ||
gcpCredentialEnvVar := corev1.EnvVar{ | ||
Name: "GOOGLE_APPLICATION_CREDENTIALS", | ||
Value: fmt.Sprintf("%s/service-account.json", mountPath), | ||
} | ||
containerSpec.Env = append(containerSpec.Env, gcpCredentialEnvVar) | ||
updatedPodSpec.Containers[idx] = containerSpec | ||
} | ||
|
||
if containerExist { | ||
updatedPodSpec.Volumes = append(updatedPodSpec.Volumes, secretVolume) | ||
} | ||
return *updatedPodSpec | ||
} | ||
|
||
func createVolumeFromSecret(secretName string) corev1.Volume { | ||
return corev1.Volume{ | ||
Name: "iam-secret", | ||
VolumeSource: corev1.VolumeSource{ | ||
Secret: &corev1.SecretVolumeSource{ | ||
SecretName: secretName, | ||
}, | ||
}, | ||
} | ||
} |
Oops, something went wrong.