mirror of
https://github.com/open-cluster-management-io/ocm.git
synced 2026-02-14 18:09:57 +00:00
Some checks failed
Post / images (amd64, placement) (push) Failing after 50s
Post / images (amd64, registration) (push) Failing after 41s
Post / images (amd64, registration-operator) (push) Failing after 40s
Post / images (amd64, work) (push) Failing after 44s
Post / images (arm64, addon-manager) (push) Failing after 41s
Post / images (arm64, placement) (push) Failing after 42s
Post / images (arm64, registration) (push) Failing after 41s
Post / images (amd64, addon-manager) (push) Failing after 5m29s
Post / images (arm64, registration-operator) (push) Failing after 43s
Post / images (arm64, work) (push) Failing after 5m35s
Post / image manifest (addon-manager) (push) Has been skipped
Post / image manifest (placement) (push) Has been skipped
Post / image manifest (registration) (push) Has been skipped
Post / image manifest (registration-operator) (push) Has been skipped
Post / image manifest (work) (push) Has been skipped
Post / trigger clusteradm e2e (push) Has been skipped
Post / coverage (push) Failing after 40m4s
Scorecard supply-chain security / Scorecard analysis (push) Failing after 4m1s
Signed-off-by: Yang Le <yangle@redhat.com>
90 lines
2.8 KiB
Go
90 lines
2.8 KiB
Go
package factory
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/spf13/pflag"
|
|
|
|
operatorv1 "open-cluster-management.io/api/operator/v1"
|
|
|
|
"open-cluster-management.io/ocm/pkg/registration/register"
|
|
awsirsa "open-cluster-management.io/ocm/pkg/registration/register/aws_irsa"
|
|
"open-cluster-management.io/ocm/pkg/registration/register/csr"
|
|
"open-cluster-management.io/ocm/pkg/registration/register/grpc"
|
|
"open-cluster-management.io/ocm/pkg/registration/register/token"
|
|
)
|
|
|
|
type Options struct {
|
|
RegistrationAuth string
|
|
CSROption *csr.Option
|
|
AWSIRSAOption *awsirsa.AWSOption
|
|
GRPCOption *grpc.Option
|
|
TokenOption *token.Option
|
|
|
|
// AddonKubeClientRegistrationAuth specifies the authentication method for addons
|
|
// with registration type KubeClient. Possible values are "csr" (default) and "token".
|
|
AddonKubeClientRegistrationAuth string
|
|
}
|
|
|
|
func NewOptions() *Options {
|
|
return &Options{
|
|
CSROption: csr.NewCSROption(),
|
|
AWSIRSAOption: awsirsa.NewAWSOption(),
|
|
GRPCOption: grpc.NewOptions(),
|
|
TokenOption: token.NewTokenOption(),
|
|
AddonKubeClientRegistrationAuth: "csr", // default to csr
|
|
}
|
|
}
|
|
|
|
func (s *Options) AddFlags(fs *pflag.FlagSet) {
|
|
fs.StringVar(&s.RegistrationAuth, "registration-auth", s.RegistrationAuth,
|
|
"The type of authentication to use to authenticate with hub.")
|
|
fs.StringVar(&s.AddonKubeClientRegistrationAuth, "addon-kubeclient-registration-auth", s.AddonKubeClientRegistrationAuth,
|
|
"The authentication method for addons with registration type KubeClient. Possible values are 'csr' (default) and 'token'.")
|
|
s.CSROption.AddFlags(fs)
|
|
s.AWSIRSAOption.AddFlags(fs)
|
|
s.GRPCOption.AddFlags(fs)
|
|
s.TokenOption.AddFlags(fs)
|
|
}
|
|
|
|
func (s *Options) Validate() error {
|
|
switch s.AddonKubeClientRegistrationAuth {
|
|
case "", "csr", "token":
|
|
// valid values
|
|
default:
|
|
return fmt.Errorf("unsupported addon-kubeclient-registration-auth: %s", s.AddonKubeClientRegistrationAuth)
|
|
}
|
|
|
|
switch s.RegistrationAuth {
|
|
case operatorv1.AwsIrsaAuthType:
|
|
return s.AWSIRSAOption.Validate()
|
|
case operatorv1.GRPCAuthType:
|
|
return s.GRPCOption.Validate()
|
|
default:
|
|
return s.CSROption.Validate()
|
|
}
|
|
}
|
|
|
|
func (s *Options) GetKubeClientAuth() string {
|
|
return s.AddonKubeClientRegistrationAuth
|
|
}
|
|
|
|
func (s *Options) GetCSRConfiguration() register.CSRConfiguration {
|
|
return s.CSROption
|
|
}
|
|
|
|
func (s *Options) GetTokenConfiguration() register.TokenConfiguration {
|
|
return s.TokenOption
|
|
}
|
|
|
|
func (s *Options) Driver(secretOption register.SecretOption) (register.RegisterDriver, error) {
|
|
switch s.RegistrationAuth {
|
|
case operatorv1.AwsIrsaAuthType:
|
|
return awsirsa.NewAWSIRSADriver(s.AWSIRSAOption, secretOption), nil
|
|
case operatorv1.GRPCAuthType:
|
|
return grpc.NewGRPCDriver(s.GRPCOption, s.CSROption, secretOption)
|
|
default:
|
|
return csr.NewCSRDriver(s.CSROption, secretOption)
|
|
}
|
|
}
|