Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gardenlogin install hint #214

Merged
merged 3 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions internal/gardenclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
openstackv1alpha1 "github.com/gardener/gardener-extension-provider-openstack/pkg/apis/openstack/v1alpha1"
gardencore "github.com/gardener/gardener/pkg/apis/core"
gardencorev1beta1 "github.com/gardener/gardener/pkg/apis/core/v1beta1"
gardenoperationsv1alpha1 "github.com/gardener/gardener/pkg/apis/operations/v1alpha1"
operationsv1alpha1 "github.com/gardener/gardener/pkg/apis/operations/v1alpha1"
seedmanagementv1alpha1 "github.com/gardener/gardener/pkg/apis/seedmanagement/v1alpha1"
authenticationv1 "k8s.io/api/authentication/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -83,9 +83,9 @@ type Client interface {
GetShootOfManagedSeed(ctx context.Context, name string) (*seedmanagementv1alpha1.Shoot, error)

// ListBastions returns all Gardener bastion resources, filtered by a list option
ListBastions(ctx context.Context, opts ...client.ListOption) (*gardenoperationsv1alpha1.BastionList, error)
ListBastions(ctx context.Context, opts ...client.ListOption) (*operationsv1alpha1.BastionList, error)
// PatchBastion patches an existing bastion to match newBastion using the merge patch strategy
PatchBastion(ctx context.Context, newBastion, oldBastion *gardenoperationsv1alpha1.Bastion) error
PatchBastion(ctx context.Context, newBastion, oldBastion *operationsv1alpha1.Bastion) error

// Creates a token review for a user with token authentication
CreateTokenReview(ctx context.Context, token string) (*authenticationv1.TokenReview, error)
Expand Down Expand Up @@ -292,8 +292,8 @@ func (g *clientImpl) GetShootOfManagedSeed(ctx context.Context, name string) (*s
return managedSeed.Spec.Shoot, nil
}

func (g *clientImpl) ListBastions(ctx context.Context, opts ...client.ListOption) (*gardenoperationsv1alpha1.BastionList, error) {
bastionList := &gardenoperationsv1alpha1.BastionList{}
func (g *clientImpl) ListBastions(ctx context.Context, opts ...client.ListOption) (*operationsv1alpha1.BastionList, error) {
bastionList := &operationsv1alpha1.BastionList{}

if err := g.resolveListOptions(ctx, opts...); err != nil {
return nil, err
Expand All @@ -306,7 +306,7 @@ func (g *clientImpl) ListBastions(ctx context.Context, opts ...client.ListOption
return bastionList, nil
}

func (g *clientImpl) PatchBastion(ctx context.Context, newBastion, oldBastion *gardenoperationsv1alpha1.Bastion) error {
func (g *clientImpl) PatchBastion(ctx context.Context, newBastion, oldBastion *operationsv1alpha1.Bastion) error {
return g.c.Patch(ctx, newBastion, client.MergeFrom(oldBastion))
}

Expand Down
7 changes: 3 additions & 4 deletions internal/gardenclient/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,11 @@ var _ = Describe("Client", func() {

Expect(rawConfig.AuthInfos).To(HaveLen(1))
authInfo := rawConfig.AuthInfos[context.AuthInfo]
Expect(authInfo.Exec.Command).To(Equal("kubectl"))
Expect(authInfo.Exec.Command).To(Equal("kubectl-gardenlogin"))
Expect(authInfo.Exec.Args).To(Equal([]string{
"gardenlogin",
"get-client-certificate",
}))
Expect(authInfo.Exec.InstallHint).ToNot(BeEmpty())
})

Context("legacy kubeconfig", func() {
Expand All @@ -239,9 +239,8 @@ var _ = Describe("Client", func() {

Expect(rawConfig.AuthInfos).To(HaveLen(1))
authInfo := rawConfig.AuthInfos[context.AuthInfo]
Expect(authInfo.Exec.Command).To(Equal("kubectl"))
Expect(authInfo.Exec.Command).To(Equal("kubectl-gardenlogin"))
Expect(authInfo.Exec.Args).To(Equal([]string{
"gardenlogin",
"get-client-certificate",
fmt.Sprintf("--name=%s", shootName),
fmt.Sprintf("--namespace=%s", namespace),
Expand Down
5 changes: 2 additions & 3 deletions internal/gardenclient/shoot_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ func (k *shootKubeconfigRequest) generate(legacy bool) (*clientcmdapi.Config, er
var extension *execPluginConfig

args := []string{
"gardenlogin",
"get-client-certificate",
}

Expand All @@ -157,11 +156,11 @@ func (k *shootKubeconfigRequest) generate(legacy bool) (*clientcmdapi.Config, er

authInfo := clientcmdapi.NewAuthInfo()
authInfo.Exec = &clientcmdapi.ExecConfig{
Command: "kubectl",
Command: "kubectl-gardenlogin",
Args: args,
Env: nil,
APIVersion: clientauthenticationv1beta1.SchemeGroupVersion.String(),
InstallHint: "",
InstallHint: "Follow the instructions on https://github.com/gardener/gardenlogin#installation to install gardenlogin",
ProvideClusterInfo: true,

// gardenlogin kubectl auth plugin does not require stdin itself,
Expand Down
12 changes: 6 additions & 6 deletions pkg/cmd/sshpatch/bastionlistpatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"path"

gardencore "github.com/gardener/gardener/pkg/apis/core"
gardenoperationsv1alpha1 "github.com/gardener/gardener/pkg/apis/operations/v1alpha1"
operationsv1alpha1 "github.com/gardener/gardener/pkg/apis/operations/v1alpha1"
clientauthentication "k8s.io/client-go/pkg/apis/clientauthentication"
"k8s.io/client-go/tools/clientcmd"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
Expand All @@ -28,12 +28,12 @@ import (

type bastionLister interface {
// List lists all bastions for the current target
List(ctx context.Context) ([]gardenoperationsv1alpha1.Bastion, error)
List(ctx context.Context) ([]operationsv1alpha1.Bastion, error)
}

type bastionPatcher interface {
// Patch patches an existing bastion
Patch(ctx context.Context, oldBastion, newBastion *gardenoperationsv1alpha1.Bastion) error
Patch(ctx context.Context, oldBastion, newBastion *operationsv1alpha1.Bastion) error
}

//go:generate mockgen -source=./ssh_patch_userbastionlister.go -destination=./mocks/mock_ssh_patch_userbastionlister.go -package=mocks github.com/gardener/gardenctl-v2/pkg/cmd/ssh bastionListPatcher
Expand Down Expand Up @@ -77,7 +77,7 @@ func newUserBastionListPatcher(ctx context.Context, manager target.Manager) (bas
}, nil
}

func (u *userBastionListPatcherImpl) List(ctx context.Context) ([]gardenoperationsv1alpha1.Bastion, error) {
func (u *userBastionListPatcherImpl) List(ctx context.Context) ([]operationsv1alpha1.Bastion, error) {
authInfo, err := u.AuthInfo(u.clientConfig)
if err != nil {
return nil, fmt.Errorf("could not get authInfo: %w", err)
Expand All @@ -100,7 +100,7 @@ func (u *userBastionListPatcherImpl) List(ctx context.Context) ([]gardenoperatio
listOption[gardencore.ShootSeedName] = u.target.SeedName()
}

var bastionsOfUser []gardenoperationsv1alpha1.Bastion
var bastionsOfUser []operationsv1alpha1.Bastion

list, err := u.gardenClient.ListBastions(ctx, listOption)
if err != nil {
Expand Down Expand Up @@ -216,6 +216,6 @@ func (u *userBastionListPatcherImpl) AuthInfo(clientConfig clientcmd.ClientConfi
return authInfo, nil
}

func (u *userBastionListPatcherImpl) Patch(ctx context.Context, newBastion, oldBastion *gardenoperationsv1alpha1.Bastion) error {
func (u *userBastionListPatcherImpl) Patch(ctx context.Context, newBastion, oldBastion *operationsv1alpha1.Bastion) error {
return u.gardenClient.PatchBastion(ctx, newBastion, oldBastion)
}
8 changes: 4 additions & 4 deletions pkg/cmd/sshpatch/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"net"
"time"

gardenoperationsv1alpha1 "github.com/gardener/gardener/pkg/apis/operations/v1alpha1"
operationsv1alpha1 "github.com/gardener/gardener/pkg/apis/operations/v1alpha1"
"github.com/spf13/cobra"
networkingv1 "k8s.io/api/networking/v1"

Expand All @@ -27,7 +27,7 @@ type options struct {
ssh.AccessConfig

// Bastion is the Bastion corresponding to the provided BastionName
Bastion *gardenoperationsv1alpha1.Bastion
Bastion *operationsv1alpha1.Bastion

// bastionPatcher lists bastions created by the current user
bastionPatcher bastionPatcher
Expand All @@ -43,7 +43,7 @@ func newOptions(ioStreams util.IOStreams) *options {
}

func (o *options) patchBastionIngress(ctx context.Context) error {
var policies []gardenoperationsv1alpha1.BastionIngressPolicy
var policies []operationsv1alpha1.BastionIngressPolicy

oldBastion := o.Bastion.DeepCopy()

Expand All @@ -65,7 +65,7 @@ func (o *options) patchBastionIngress(ctx context.Context) error {
}
}

policies = append(policies, gardenoperationsv1alpha1.BastionIngressPolicy{
policies = append(policies, operationsv1alpha1.BastionIngressPolicy{
IPBlock: networkingv1.IPBlock{
CIDR: cidr,
},
Expand Down
42 changes: 21 additions & 21 deletions pkg/cmd/sshpatch/sshpatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"time"

gardencorev1beta1 "github.com/gardener/gardener/pkg/apis/core/v1beta1"
gardenoperationsv1alpha1 "github.com/gardener/gardener/pkg/apis/operations/v1alpha1"
operationsv1alpha1 "github.com/gardener/gardener/pkg/apis/operations/v1alpha1"
gardensecrets "github.com/gardener/gardener/pkg/utils/secrets"
"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo"
Expand Down Expand Up @@ -60,15 +60,15 @@ var _ = Describe("SSH Patch Command", func() {
testSeed *gardencorev1beta1.Seed
testShoot *gardencorev1beta1.Shoot
apiConfig *clientcmdapi.Config
bastionDefaultPolicies []gardenoperationsv1alpha1.BastionIngressPolicy
bastionDefaultPolicies []operationsv1alpha1.BastionIngressPolicy
)

// helpers
var (
ctxType = reflect.TypeOf((*context.Context)(nil)).Elem()
isCtx = gomock.AssignableToTypeOf(ctxType)
createBastion = func(createdBy, bastionName string) gardenoperationsv1alpha1.Bastion {
return gardenoperationsv1alpha1.Bastion{
createBastion = func(createdBy, bastionName string) operationsv1alpha1.Bastion {
return operationsv1alpha1.Bastion{
ObjectMeta: metav1.ObjectMeta{
Name: bastionName,
Namespace: testShoot.Namespace,
Expand All @@ -80,7 +80,7 @@ var _ = Describe("SSH Patch Command", func() {
Time: now,
},
},
Spec: gardenoperationsv1alpha1.BastionSpec{
Spec: operationsv1alpha1.BastionSpec{
ShootRef: corev1.LocalObjectReference{
Name: testShoot.Name,
},
Expand Down Expand Up @@ -173,7 +173,7 @@ var _ = Describe("SSH Patch Command", func() {
},
}

bastionDefaultPolicies = []gardenoperationsv1alpha1.BastionIngressPolicy{{
bastionDefaultPolicies = []operationsv1alpha1.BastionIngressPolicy{{
IPBlock: networkingv1.IPBlock{
CIDR: "1.1.1.1/16",
},
Expand Down Expand Up @@ -216,7 +216,7 @@ var _ = Describe("SSH Patch Command", func() {

Describe("sshPatchOptions", func() {
Describe("Validate", func() {
var fakeBastion gardenoperationsv1alpha1.Bastion
var fakeBastion operationsv1alpha1.Bastion

BeforeEach(func() {
fakeBastion = createBastion("user", "bastion-name")
Expand All @@ -241,8 +241,8 @@ var _ = Describe("SSH Patch Command", func() {
o := sshpatch.NewTestOptions()
cmd := sshpatch.NewCmdSSHPatch(factory, o.IOStreams)

fakeBastionList := &gardenoperationsv1alpha1.BastionList{
Items: []gardenoperationsv1alpha1.Bastion{
fakeBastionList := &operationsv1alpha1.BastionList{
Items: []operationsv1alpha1.Bastion{
createBastion("other-user", "other-user-bastion1"),
createBastion("other-user", "other-user-bastion2"),
},
Expand All @@ -260,8 +260,8 @@ var _ = Describe("SSH Patch Command", func() {
o := sshpatch.NewTestOptions()
cmd := sshpatch.NewCmdSSHPatch(factory, o.IOStreams)

fakeBastionList := &gardenoperationsv1alpha1.BastionList{
Items: []gardenoperationsv1alpha1.Bastion{
fakeBastionList := &operationsv1alpha1.BastionList{
Items: []operationsv1alpha1.Bastion{
createBastion(defaultUserName, defaultUserName+"-bastion1"),
createBastion("other-user", "other-user-bastion1"),
createBastion("other-user", "other-user-bastion2"),
Expand All @@ -284,8 +284,8 @@ var _ = Describe("SSH Patch Command", func() {
o := sshpatch.NewTestOptions()
cmd := sshpatch.NewCmdSSHPatch(factory, o.IOStreams)

fakeBastionList := &gardenoperationsv1alpha1.BastionList{
Items: []gardenoperationsv1alpha1.Bastion{
fakeBastionList := &operationsv1alpha1.BastionList{
Items: []operationsv1alpha1.Bastion{
createBastion(defaultUserName, defaultUserName+"-bastion1"),
createBastion(defaultUserName, defaultUserName+"-bastion2"),
createBastion("other-user", "other-user-bastion1"),
Expand All @@ -308,8 +308,8 @@ var _ = Describe("SSH Patch Command", func() {
o := sshpatch.NewTestOptions()
cmd := sshpatch.NewCmdSSHPatch(factory, o.IOStreams)

fakeBastionList := &gardenoperationsv1alpha1.BastionList{
Items: []gardenoperationsv1alpha1.Bastion{
fakeBastionList := &operationsv1alpha1.BastionList{
Items: []operationsv1alpha1.Bastion{
createBastion(defaultUserName, defaultUserName+"-bastion1"),
createBastion(defaultUserName, defaultUserName+"-bastion2"),
createBastion("other-user", "other-user-bastion1"),
Expand All @@ -334,8 +334,8 @@ var _ = Describe("SSH Patch Command", func() {

BeforeEach(func() {
fakeBastion := createBastion(defaultUserName, defaultUserName+"-bastion1")
fakeBastionList := &gardenoperationsv1alpha1.BastionList{
Items: []gardenoperationsv1alpha1.Bastion{
fakeBastionList := &operationsv1alpha1.BastionList{
Items: []operationsv1alpha1.Bastion{
fakeBastion,
},
}
Expand Down Expand Up @@ -375,8 +375,8 @@ var _ = Describe("SSH Patch Command", func() {
streams, _, _, _ := util.NewTestIOStreams()
cmd := sshpatch.NewCmdSSHPatch(factory, streams)

fakeBastionList := &gardenoperationsv1alpha1.BastionList{
Items: []gardenoperationsv1alpha1.Bastion{
fakeBastionList := &operationsv1alpha1.BastionList{
Items: []operationsv1alpha1.Bastion{
createBastion(defaultUserName, prefix+"-bastion1"),
createBastion(defaultUserName, prefix+"-bastion2"),
createBastion(defaultUserName, "prefix2-bastion1"),
Expand All @@ -403,8 +403,8 @@ var _ = Describe("SSH Patch Command", func() {
var patchLister *sshpatch.TestUserBastionListPatcherImpl

BeforeEach(func() {
fakeBastionList := &gardenoperationsv1alpha1.BastionList{
Items: []gardenoperationsv1alpha1.Bastion{
fakeBastionList := &operationsv1alpha1.BastionList{
Items: []operationsv1alpha1.Bastion{
createBastion("client-cn", "fake-bastion"),
},
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/target/mocks/mock_manager.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.