generated from kyma-project/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into local_dev_makefile
- Loading branch information
Showing
8 changed files
with
122 additions
and
33 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
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
Empty file.
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 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 |
---|---|---|
@@ -1,8 +1,59 @@ | ||
package gardener | ||
|
||
import ( | ||
"context" | ||
|
||
authenticationv1alpha1 "github.com/gardener/gardener/pkg/apis/authentication/v1alpha1" | ||
"github.com/gardener/gardener/pkg/apis/core/v1beta1" | ||
"github.com/pkg/errors" | ||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
gardenerClient "sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
type KubeconfigProvider struct { | ||
shootNamespace string | ||
shootClient ShootClient | ||
dynamicKubeconfigAPI DynamicKubeconfigAPI | ||
expirationInSeconds int64 | ||
} | ||
|
||
type ShootClient interface { | ||
Get(ctx context.Context, name string, opts v1.GetOptions) (*v1beta1.Shoot, error) | ||
} | ||
|
||
type DynamicKubeconfigAPI interface { | ||
Create(ctx context.Context, obj gardenerClient.Object, subResource gardenerClient.Object, opts ...gardenerClient.SubResourceCreateOption) error | ||
} | ||
|
||
func (receiver KubeconfigProvider) Fetch(shootName string) (string, error) { | ||
return "kubeconfig-" + shootName, nil | ||
func NewKubeconfigProvider( | ||
shootClient ShootClient, | ||
dynamicKubeconfigAPI DynamicKubeconfigAPI, | ||
shootNamespace string, | ||
expirationInSeconds int64) KubeconfigProvider { | ||
return KubeconfigProvider{ | ||
shootClient: shootClient, | ||
dynamicKubeconfigAPI: dynamicKubeconfigAPI, | ||
shootNamespace: shootNamespace, | ||
expirationInSeconds: expirationInSeconds, | ||
} | ||
} | ||
|
||
func (kp KubeconfigProvider) Fetch(shootName string) (string, error) { | ||
shoot, err := kp.shootClient.Get(context.Background(), shootName, v1.GetOptions{}) | ||
if err != nil { | ||
return "", errors.Wrap(err, "failed to get shoot") | ||
} | ||
|
||
adminKubeconfigRequest := authenticationv1alpha1.AdminKubeconfigRequest{ | ||
Spec: authenticationv1alpha1.AdminKubeconfigRequestSpec{ | ||
ExpirationSeconds: &kp.expirationInSeconds, | ||
}, | ||
} | ||
|
||
err = kp.dynamicKubeconfigAPI.Create(context.Background(), shoot, &adminKubeconfigRequest) | ||
if err != nil { | ||
return "", errors.Wrap(err, "failed to create AdminKubeconfigRequest") | ||
} | ||
|
||
return string(adminKubeconfigRequest.Status.Kubeconfig), 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