Skip to content

Commit b27735b

Browse files
committed
Define type alias for getServiceAccount function
Signed-off-by: Anish Ramasekar <[email protected]>
1 parent fb98a59 commit b27735b

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

pkg/credentialprovider/plugin/plugin.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ var (
7373
}
7474
)
7575

76+
// GetServiceAccountFunc is a function type that returns a service account token for the given namespace and name.
77+
type GetServiceAccountFunc func(namespace, name string) (*v1.ServiceAccount, error)
78+
79+
// getServiceAccountTokenFunc is a function type that returns a service account token for the given namespace and name.
80+
type getServiceAccountTokenFunc func(namespace, name string, tr *authenticationv1.TokenRequest) (*authenticationv1.TokenRequest, error)
81+
7682
func init() {
7783
install.Install(scheme)
7884
kubeletconfig.AddToScheme(scheme)
@@ -84,8 +90,8 @@ func init() {
8490
// RegisterCredentialProviderPlugins is called from kubelet to register external credential provider
8591
// plugins according to the CredentialProviderConfig config file.
8692
func RegisterCredentialProviderPlugins(pluginConfigFile, pluginBinDir string,
87-
getServiceAccountToken func(namespace, name string, tr *authenticationv1.TokenRequest) (*authenticationv1.TokenRequest, error),
88-
getServiceAccount func(namespace, name string) (*v1.ServiceAccount, error),
93+
getServiceAccountToken getServiceAccountTokenFunc,
94+
getServiceAccount GetServiceAccountFunc,
8995
) error {
9096
if _, err := os.Stat(pluginBinDir); err != nil {
9197
if os.IsNotExist(err) {
@@ -133,8 +139,8 @@ func RegisterCredentialProviderPlugins(pluginConfigFile, pluginBinDir string,
133139

134140
// newPluginProvider returns a new pluginProvider based on the credential provider config.
135141
func newPluginProvider(pluginBinDir string, provider kubeletconfig.CredentialProvider,
136-
getServiceAccountToken func(namespace, name string, tr *authenticationv1.TokenRequest) (*authenticationv1.TokenRequest, error),
137-
getServiceAccount func(namespace, name string) (*v1.ServiceAccount, error),
142+
getServiceAccountToken getServiceAccountTokenFunc,
143+
getServiceAccount GetServiceAccountFunc,
138144
) (*pluginProvider, error) {
139145
mediaType := "application/json"
140146
info, ok := runtime.SerializerInfoForMediaType(codecs.SupportedMediaTypes(), mediaType)
@@ -200,16 +206,16 @@ type pluginProvider struct {
200206
type serviceAccountProvider struct {
201207
audience string
202208
requireServiceAccount bool
203-
getServiceAccountFunc func(namespace, name string) (*v1.ServiceAccount, error)
204-
getServiceAccountTokenFunc func(podNamespace, serviceAccountName string, tr *authenticationv1.TokenRequest) (*authenticationv1.TokenRequest, error)
209+
getServiceAccountFunc GetServiceAccountFunc
210+
getServiceAccountTokenFunc getServiceAccountTokenFunc
205211
requiredServiceAccountAnnotationKeys []string
206212
optionalServiceAccountAnnotationKeys []string
207213
}
208214

209215
func newServiceAccountProvider(
210216
provider kubeletconfig.CredentialProvider,
211-
getServiceAccount func(namespace, name string) (*v1.ServiceAccount, error),
212-
getServiceAccountToken func(namespace, name string, tr *authenticationv1.TokenRequest) (*authenticationv1.TokenRequest, error),
217+
getServiceAccount GetServiceAccountFunc,
218+
getServiceAccountToken getServiceAccountTokenFunc,
213219
) *serviceAccountProvider {
214220
featureGateEnabled := utilfeature.DefaultFeatureGate.Enabled(features.KubeletServiceAccountTokenForCredentialProviders)
215221
serviceAccountTokenAudienceSet := provider.TokenAttributes != nil && len(provider.TokenAttributes.ServiceAccountTokenAudience) > 0

pkg/kubelet/kuberuntime/kuberuntime_manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ func NewKubeGenericRuntimeManager(
224224
podPullingTimeRecorder images.ImagePodPullingTimeRecorder,
225225
tracerProvider trace.TracerProvider,
226226
tokenManager *token.Manager,
227-
getServiceAccount func(string, string) (*v1.ServiceAccount, error),
227+
getServiceAccount plugin.GetServiceAccountFunc,
228228
) (KubeGenericRuntime, error) {
229229
ctx := context.Background()
230230
runtimeService = newInstrumentedRuntimeService(runtimeService)

0 commit comments

Comments
 (0)