-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add credential provider option to kubeadm
- Loading branch information
Showing
7 changed files
with
370 additions
and
290 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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package kubeadm | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
"github.com/openconfig/kne/exec/run" | ||
) | ||
|
||
const ( | ||
kubeadmFlagPath = "/var/lib/kubelet/kubeadm-flags.env" | ||
) | ||
|
||
// EnableCredentialProvider enables a credential provider according | ||
// to the specified config file on the kubelet. | ||
func EnableCredentialProvider(cfgPath string) error { | ||
if err := run.LogCommand("sudo", "kubeadm", "upgrade", "node", "phase", "kubelet-config"); err != nil { | ||
return err | ||
} | ||
b, err := os.ReadFile(kubeadmFlagPath) | ||
if err != nil { | ||
return err | ||
} | ||
s, _ := strings.CutSuffix(string(b), `"`) | ||
s = fmt.Sprintf(`%s --image-credential-provider-config=%s --image-credential-provider-bin-dir=/etc/kubernetes/bin"`, s, cfgPath) | ||
f, err := os.Create(kubeadmFlagPath) | ||
if err != nil { | ||
return err | ||
} | ||
if _, err := f.WriteString(s); err != nil { | ||
return err | ||
} | ||
if err := run.LogCommand("sudo", "systemctl", "restart", "kubelet"); err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
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 was deleted.
Oops, something went wrong.
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,14 @@ | ||
kind: CredentialProviderConfig | ||
apiVersion: kubelet.config.k8s.io/v1 | ||
providers: | ||
- name: auth-provider-gcp | ||
apiVersion: credentialprovider.kubelet.k8s.io/v1 | ||
matchImages: | ||
- "container.cloud.google.com" | ||
- "gcr.io" | ||
- "*.gcr.io" | ||
- "*.pkg.dev" | ||
args: | ||
- get-credentials | ||
- --v=3 | ||
defaultCacheDuration: 1m |
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
Oops, something went wrong.