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

Reimplement the register-member command #33

Merged
merged 22 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
de2d935
Reimplement the register-member command to not disable automatic appr…
metlos Apr 19, 2024
a65406e
yes, mister linter, thank you mister linter.
metlos Apr 19, 2024
c026804
Merge branch 'master' into register-member-using-spc
metlos Apr 22, 2024
c123748
Merge branch 'master' into register-member-using-spc
MatousJobanek Apr 23, 2024
fdc1345
Merge branch 'master' into register-member-using-spc
MatousJobanek Apr 24, 2024
9a8f839
Add test cases for host cluster urls
metlos Apr 25, 2024
8ad936a
Split up the registerMember command into info-gathering, validation and
metlos Apr 30, 2024
d3bc8ce
Merge remote-tracking branch 'upstream/master' into register-member-u…
metlos Apr 30, 2024
3313cb4
Merge branch 'master' into register-member-using-spc
mfrancisc May 8, 2024
5630264
Simplify the register-member command to be idempotent,
metlos May 9, 2024
c706f4e
Merge remote-tracking branch 'origin/register-member-using-spc' into …
metlos May 9, 2024
2308288
Make sure to append all errors to the diagnostic output
metlos May 22, 2024
f8e3ef9
Renaming and small refactoring.
metlos May 22, 2024
24c9712
Fix a typo in the function name
metlos May 22, 2024
0932f94
gofmt-ed.
metlos May 23, 2024
b699334
Define the defaults right in the NewRegisterMemberCmd() function for …
metlos May 23, 2024
40bb021
don't duplicate the information in the struct.
metlos May 23, 2024
55a142b
remove the notion of the ordinal now that we replaced it with a gener…
metlos May 27, 2024
c5f1e10
Add a TODO for using the generic condition functions once we're able to
metlos May 27, 2024
03b87ce
No need to make a special case for empty suffix anymore
metlos May 27, 2024
1b2f22d
Fix a typo
metlos May 27, 2024
2c6d4b6
Do away with modifying outer-scoped variables
metlos May 27, 2024
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
51 changes: 33 additions & 18 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,21 @@
return addToSchemes.AddToScheme(scheme.Scheme)
}

var DefaultNewClient = NewClient
var (
DefaultNewClient = NewClient
DefaultNewClientFromRestConfig = NewClientFromRestConfig
)

func NewClient(token, apiEndpoint string) (runtimeclient.Client, error) {
return NewClientWithTransport(token, apiEndpoint, &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true, // nolint: gosec
},
})
return NewClientWithTransport(token, apiEndpoint, newTlsVerifySkippingTransport())
}

func NewClientFromRestConfig(config *rest.Config) (runtimeclient.Client, error) {
config.Insecure = true
return newClientFromRestConfig(config)

Check warning on line 66 in pkg/client/client.go

View check run for this annotation

Codecov / codecov/patch

pkg/client/client.go#L64-L66

Added lines #L64 - L66 were not covered by tests
}

func NewClientWithTransport(token, apiEndpoint string, transport http.RoundTripper) (runtimeclient.Client, error) {
if err := AddToScheme(); err != nil {
return nil, err
}
cfg, err := clientcmd.BuildConfigFromFlags(apiEndpoint, "")
if err != nil {
return nil, err
Expand All @@ -77,14 +78,30 @@
cfg.Burst = 50
cfg.Timeout = 60 * time.Second

return newClientFromRestConfig(cfg)
}

func newClientFromRestConfig(cfg *rest.Config) (runtimeclient.Client, error) {
if err := AddToScheme(); err != nil {
return nil, err

Check warning on line 86 in pkg/client/client.go

View check run for this annotation

Codecov / codecov/patch

pkg/client/client.go#L86

Added line #L86 was not covered by tests
}

cl, err := runtimeclient.New(cfg, runtimeclient.Options{})
if err != nil {
return nil, errs.Wrap(err, "cannot create client")
return nil, fmt.Errorf("cannot create client: %w", err)
}

return cl, nil
}

func newTlsVerifySkippingTransport() http.RoundTripper {
return &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true, // nolint: gosec
},
}
}

var DefaultNewRESTClient = NewRESTClient

func NewRESTClient(token, apiEndpoint string) (*rest.RESTClient, error) {
Expand All @@ -94,12 +111,8 @@
config := &rest.Config{
BearerToken: token,
Host: apiEndpoint,
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true, // nolint: gosec
},
},
Timeout: 60 * time.Second,
Transport: newTlsVerifySkippingTransport(),
Timeout: 60 * time.Second,

Check warning on line 115 in pkg/client/client.go

View check run for this annotation

Codecov / codecov/patch

pkg/client/client.go#L114-L115

Added lines #L114 - L115 were not covered by tests
// These fields need to be set when using the REST client ¯\_(ツ)_/¯
ContentConfig: rest.ContentConfig{
GroupVersion: &authv1.SchemeGroupVersion,
Expand Down Expand Up @@ -377,5 +390,7 @@
return fmt.Sprintf("%s://%s/%s", scheme, route.Spec.Host, route.Spec.Path), nil
}

var timeout = 5 * time.Second
var retryInterval = 200 * time.Millisecond
var (
timeout = 5 * time.Second
retryInterval = 200 * time.Millisecond
)
Loading
Loading