forked from kubernetes-sigs/cluster-api-provider-openstack
-
Notifications
You must be signed in to change notification settings - Fork 2
V0.6.3 #1
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
Open
Goend
wants to merge
2
commits into
easystack:v0.6.3
Choose a base branch
from
Goend:v0.6.3
base: v0.6.3
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
V0.6.3 #1
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -21,6 +21,7 @@ import ( | |
"crypto/tls" | ||
"crypto/x509" | ||
"fmt" | ||
"github.com/gophercloud/gophercloud/openstack/identity/v3/extensions/trusts" | ||
"net/http" | ||
|
||
"github.com/gophercloud/gophercloud" | ||
|
@@ -37,13 +38,58 @@ import ( | |
infrav1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha5" | ||
) | ||
|
||
type NewAuthInfo struct { | ||
clientconfig.AuthInfo | ||
TrustID string `yaml:"trust_id,omitempty" json:"trust_id,omitempty"` | ||
} | ||
|
||
// NewCloud represents an entry in a clouds.yaml/public-clouds.yaml/secure.yaml file. | ||
type NewCloud struct { | ||
Cloud string `yaml:"cloud,omitempty" json:"cloud,omitempty"` | ||
Profile string `yaml:"profile,omitempty" json:"profile,omitempty"` | ||
AuthInfo *NewAuthInfo `yaml:"auth,omitempty" json:"auth,omitempty"` | ||
AuthType clientconfig.AuthType `yaml:"auth_type,omitempty" json:"auth_type,omitempty"` | ||
RegionName string `yaml:"region_name,omitempty" json:"region_name,omitempty"` | ||
Regions []clientconfig.Region `yaml:"regions,omitempty" json:"regions,omitempty"` | ||
|
||
// EndpointType and Interface both specify whether to use the public, internal, | ||
// or admin interface of a service. They should be considered synonymous, but | ||
// EndpointType will take precedence when both are specified. | ||
EndpointType string `yaml:"endpoint_type,omitempty" json:"endpoint_type,omitempty"` | ||
Interface string `yaml:"interface,omitempty" json:"interface,omitempty"` | ||
|
||
// API Version overrides. | ||
IdentityAPIVersion string `yaml:"identity_api_version,omitempty" json:"identity_api_version,omitempty"` | ||
VolumeAPIVersion string `yaml:"volume_api_version,omitempty" json:"volume_api_version,omitempty"` | ||
|
||
// Verify whether or not SSL API requests should be verified. | ||
Verify *bool `yaml:"verify,omitempty" json:"verify,omitempty"` | ||
|
||
// CACertFile a path to a CA Cert bundle that can be used as part of | ||
// verifying SSL API requests. | ||
CACertFile string `yaml:"cacert,omitempty" json:"cacert,omitempty"` | ||
|
||
// ClientCertFile a path to a client certificate to use as part of the SSL | ||
// transaction. | ||
ClientCertFile string `yaml:"cert,omitempty" json:"cert,omitempty"` | ||
|
||
// ClientKeyFile a path to a client key to use as part of the SSL | ||
// transaction. | ||
ClientKeyFile string `yaml:"key,omitempty" json:"key,omitempty"` | ||
} | ||
|
||
type NewClouds struct { | ||
Clouds map[string]NewCloud `yaml:"clouds" json:"clouds"` | ||
} | ||
|
||
const ( | ||
cloudsSecretKey = "clouds.yaml" | ||
caSecretKey = "cacert" | ||
) | ||
|
||
|
||
func NewClientFromMachine(ctx context.Context, ctrlClient client.Client, openStackMachine *infrav1.OpenStackMachine) (*gophercloud.ProviderClient, *clientconfig.ClientOpts, string, error) { | ||
var cloud clientconfig.Cloud | ||
var cloud NewCloud | ||
var caCert []byte | ||
|
||
if openStackMachine.Spec.IdentityRef != nil { | ||
|
@@ -57,7 +103,7 @@ func NewClientFromMachine(ctx context.Context, ctrlClient client.Client, openSta | |
} | ||
|
||
func NewClientFromCluster(ctx context.Context, ctrlClient client.Client, openStackCluster *infrav1.OpenStackCluster) (*gophercloud.ProviderClient, *clientconfig.ClientOpts, string, error) { | ||
var cloud clientconfig.Cloud | ||
var cloud NewCloud | ||
var caCert []byte | ||
|
||
if openStackCluster.Spec.IdentityRef != nil { | ||
|
@@ -70,10 +116,10 @@ func NewClientFromCluster(ctx context.Context, ctrlClient client.Client, openSta | |
return NewClient(cloud, caCert) | ||
} | ||
|
||
func NewClient(cloud clientconfig.Cloud, caCert []byte) (*gophercloud.ProviderClient, *clientconfig.ClientOpts, string, error) { | ||
func NewClient(cloud NewCloud, caCert []byte) (*gophercloud.ProviderClient, *clientconfig.ClientOpts, string, error) { | ||
clientOpts := new(clientconfig.ClientOpts) | ||
if cloud.AuthInfo != nil { | ||
clientOpts.AuthInfo = cloud.AuthInfo | ||
clientOpts.AuthInfo = &cloud.AuthInfo.AuthInfo | ||
clientOpts.AuthType = cloud.AuthType | ||
clientOpts.RegionName = cloud.RegionName | ||
} | ||
|
@@ -84,11 +130,11 @@ func NewClient(cloud clientconfig.Cloud, caCert []byte) (*gophercloud.ProviderCl | |
} | ||
opts.AllowReauth = true | ||
|
||
|
||
provider, err := openstack.NewClient(opts.IdentityEndpoint) | ||
if err != nil { | ||
return nil, nil, "", fmt.Errorf("create providerClient err: %v", err) | ||
} | ||
|
||
config := &tls.Config{ | ||
RootCAs: x509.NewCertPool(), | ||
MinVersion: tls.VersionTLS12, | ||
|
@@ -101,17 +147,46 @@ func NewClient(cloud clientconfig.Cloud, caCert []byte) (*gophercloud.ProviderCl | |
} | ||
|
||
provider.HTTPClient.Transport = &http.Transport{Proxy: http.ProxyFromEnvironment, TLSClientConfig: config} | ||
if klog.V(6).Enabled() { | ||
provider.HTTPClient.Transport = &osclient.RoundTripper{ | ||
Rt: provider.HTTPClient.Transport, | ||
Logger: &defaultLogger{}, | ||
provider.HTTPClient.Transport = &osclient.RoundTripper{ | ||
Rt: provider.HTTPClient.Transport, | ||
Logger: &defaultLogger{}, | ||
} | ||
if cloud.AuthInfo.TrustID!="" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 判断条件在这里 |
||
tokenauth:=tokens.AuthOptions{} | ||
tokenauth.IdentityEndpoint=opts.IdentityEndpoint | ||
tokenauth.UserID=opts.UserID | ||
tokenauth.Username=opts.Username | ||
tokenauth.Password=opts.Password | ||
tokenauth.DomainID=opts.DomainID | ||
tokenauth.DomainName=opts.DomainName | ||
tokenauth.ApplicationCredentialID=opts.ApplicationCredentialID | ||
tokenauth.ApplicationCredentialName=opts.ApplicationCredentialName | ||
tokenauth.ApplicationCredentialSecret=opts.ApplicationCredentialSecret | ||
tokenauth.AllowReauth=opts.AllowReauth | ||
if opts.Scope!=nil { | ||
tokenauth.Scope.ProjectID=opts.Scope.ProjectID | ||
tokenauth.Scope.ProjectName=opts.Scope.ProjectName | ||
tokenauth.Scope.DomainName=opts.Scope.DomainName | ||
tokenauth.Scope.DomainID=opts.Scope.DomainID | ||
} | ||
authOptsExt := trusts.AuthOptsExt{ | ||
TrustID: cloud.AuthInfo.TrustID, | ||
AuthOptionsBuilder: &tokenauth, | ||
} | ||
err = openstack.AuthenticateV3(provider, authOptsExt, gophercloud.EndpointOpts{}) | ||
if err != nil { | ||
return nil, nil, "", fmt.Errorf("providerClient authentication err: %v", err) | ||
} | ||
projectID, err := getProjectIDFromAuthResult(provider.GetAuthResult()) | ||
if err != nil { | ||
return nil, nil, "", err | ||
} | ||
return provider,clientOpts,projectID,nil | ||
} | ||
err = openstack.Authenticate(provider, *opts) | ||
if err != nil { | ||
return nil, nil, "", fmt.Errorf("providerClient authentication err: %v", err) | ||
} | ||
|
||
projectID, err := getProjectIDFromAuthResult(provider.GetAuthResult()) | ||
if err != nil { | ||
return nil, nil, "", err | ||
|
@@ -128,8 +203,8 @@ func (defaultLogger) Printf(format string, args ...interface{}) { | |
} | ||
|
||
// getCloudFromSecret extract a Cloud from the given namespace:secretName. | ||
func getCloudFromSecret(ctx context.Context, ctrlClient client.Client, secretNamespace string, secretName string, cloudName string) (clientconfig.Cloud, []byte, error) { | ||
emptyCloud := clientconfig.Cloud{} | ||
func getCloudFromSecret(ctx context.Context, ctrlClient client.Client, secretNamespace string, secretName string, cloudName string) (NewCloud, []byte, error) { | ||
emptyCloud := NewCloud{} | ||
|
||
if secretName == "" { | ||
return emptyCloud, nil, nil | ||
|
@@ -153,7 +228,7 @@ func getCloudFromSecret(ctx context.Context, ctrlClient client.Client, secretNam | |
return emptyCloud, nil, fmt.Errorf("OpenStack credentials secret %v did not contain key %v", | ||
secretName, cloudsSecretKey) | ||
} | ||
var clouds clientconfig.Clouds | ||
var clouds NewClouds | ||
if err = yaml.Unmarshal(content, &clouds); err != nil { | ||
return emptyCloud, nil, fmt.Errorf("failed to unmarshal clouds credentials stored in secret %v: %v", secretName, err) | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个 不能复用 "github.com/gophercloud/utils/openstack/clientconfig" 的 type Cloud struct {} 吗
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add annotations to machine deployment, machinedeployment.clusters.x-k8s.io/fip: "enable",and it is ok for openstackmachine
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trust 当前没有创建逻辑 如果需要 需要在capi中补充 即创建cluster资源时 需要创建trust用户
这里认证是解决创建虚拟机时使用trust用户认证 master虚拟机内部的cloud-config 生成是由KubeadmControlPlane资源下spec.files下的content内容决定的 work虚拟机是由KubeadmConfigTemplate 下template.spec.files下的content内容决定的 使用clusterctl命令行工具 在生成配置时会帮我们注入 但这里 我们应该自己完成这个配置的组装和base64并填写到这里
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"github.com/gophercloud/utils/openstack/clientconfig" 的 type Cloud struct {} 中AuthInfo 是默认不包含trust id,我将其补充了进去 外层使用NewCloud。并使用此字段的有无来决定认证的方式 只使用原来的cloud struct我无法解析应该位于auth下的trust信息 应该是不行
示例