本文整理匯總了Golang中github.com/GoogleCloudPlatform/kubernetes/pkg/api.ServiceAccount.ImagePullSecrets方法的典型用法代碼示例。如果您正苦於以下問題:Golang ServiceAccount.ImagePullSecrets方法的具體用法?Golang ServiceAccount.ImagePullSecrets怎麽用?Golang ServiceAccount.ImagePullSecrets使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/GoogleCloudPlatform/kubernetes/pkg/api.ServiceAccount
的用法示例。
在下文中一共展示了ServiceAccount.ImagePullSecrets方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: addSecretsToServiceAccount
// TODO: when Secrets in kapi.ServiceAccount get changed to MountSecrets and represented by LocalObjectReferences, this can be
// refactored to reuse the addition code better
// addSecretsToServiceAccount adds secrets to the service account, either as pull secrets, mount secrets, or both.
func (o AddSecretOptions) addSecretsToServiceAccount(serviceaccount *kapi.ServiceAccount) error {
updated := false
newSecrets, err := o.getSecrets()
if err != nil {
return err
}
newSecretNames := getSecretNames(newSecrets)
if o.ForMount {
currentSecrets := getMountSecretNames(serviceaccount)
secretsToAdd := newSecretNames.Difference(currentSecrets)
for _, secretName := range secretsToAdd.List() {
serviceaccount.Secrets = append(serviceaccount.Secrets, kapi.ObjectReference{Name: secretName})
updated = true
}
}
if o.ForPull {
currentSecrets := getPullSecretNames(serviceaccount)
secretsToAdd := newSecretNames.Difference(currentSecrets)
for _, secretName := range secretsToAdd.List() {
serviceaccount.ImagePullSecrets = append(serviceaccount.ImagePullSecrets, kapi.LocalObjectReference{Name: secretName})
updated = true
}
}
if updated {
_, err = o.ClientInterface.ServiceAccounts(o.Namespace).Update(serviceaccount)
return err
}
return nil
}
示例2: AddSecretsToSAPullSecrets
func (o AddSecretOptions) AddSecretsToSAPullSecrets(serviceAccount *api.ServiceAccount) (*api.ServiceAccount, error) {
secrets, err := o.getSecrets()
if err != nil {
return nil, err
}
currentSecrets := util.StringSet{}
for _, secretRef := range serviceAccount.ImagePullSecrets {
currentSecrets.Insert(secretRef.Name)
}
for _, secret := range secrets {
if currentSecrets.Has(secret.Name) {
continue
}
serviceAccount.ImagePullSecrets = append(serviceAccount.ImagePullSecrets, api.LocalObjectReference{Name: secret.Name})
currentSecrets.Insert(secret.Name)
}
return o.ClientInterface.ServiceAccounts(o.Namespace).Update(serviceAccount)
}