Skip to content

Commit

Permalink
fix: retain pod spec volume when its name has default token prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
wy-lucky committed Mar 22, 2024
1 parent c8c5d84 commit e831329
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pkg/controllers/sync/dispatch/retain.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ import (

const (
// see serviceaccount admission plugin in kubernetes
ServiceAccountVolumeNamePrefix = "kube-api-access-"
ServiceAccountVolumeNameKubeAPIAccessPrefix = "kube-api-access-"
// see serviceaccount admission plugin in kubernetes
ServiceAccountVolumeNameDefaultTokenPrefix = "default-token-"
//nolint:gosec
DefaultAPITokenMountPath = "/var/run/secrets/kubernetes.io/serviceaccount"
)
Expand Down Expand Up @@ -432,7 +434,8 @@ func findServiceAccountVolume(pod *unstructured.Unstructured) (volume map[string
}

// see serviceaccount admission plugin
if strings.HasPrefix(name, ServiceAccountVolumeNamePrefix) {
if strings.HasPrefix(name, ServiceAccountVolumeNameKubeAPIAccessPrefix) ||
strings.HasPrefix(name, ServiceAccountVolumeNameDefaultTokenPrefix) {
return volume, i, true
}
}
Expand Down

0 comments on commit e831329

Please sign in to comment.