Skip to content

Commit

Permalink
fix get activedirectory authconfig error
Browse files Browse the repository at this point in the history
  • Loading branch information
JacieChao committed Mar 30, 2023
1 parent 01bee0f commit 6d016d0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
21 changes: 11 additions & 10 deletions tool/activedirectory.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package tool

import (
"context"
"crypto/x509"
"encoding/json"
"fmt"
"k8s.io/apimachinery/pkg/runtime/schema"
"strings"

managementv3 "github.com/JacieChao/rancher-upgrade-authtool/pkg/generated/controllers/management.cattle.io/v3"
"github.com/mitchellh/mapstructure"
v32 "github.com/rancher/rancher/pkg/apis/management.cattle.io/v3"
v3client "github.com/rancher/rancher/pkg/client/generated/management/v3"
"github.com/rancher/wrangler/pkg/unstructured"
"github.com/sirupsen/logrus"
"gomodules.xyz/jsonpatch/v2"

Expand All @@ -37,7 +38,7 @@ func (au *ADAuthTool) NewAuthTool(management managementv3.Interface, coreClient
au.management = management
au.coreClient = coreClient
au.client = client
adConfig, caPool, err := GetActiveDirectoryConfig(management, coreClient)
adConfig, caPool, err := GetActiveDirectoryConfig(au.client, au.coreClient)
if err != nil {
return err
}
Expand Down Expand Up @@ -133,17 +134,17 @@ func (au *ADAuthTool) PrintManualCheckData() {
au.print()
}

func GetActiveDirectoryConfig(management managementv3.Interface, coreClient v1.CoreV1Interface) (*v32.ActiveDirectoryConfig, *x509.CertPool, error) {
authConfigObj, err := management.AuthConfig().Get(ActiveDirectoryAuth, metav1.GetOptions{})
if err != nil {
return nil, nil, fmt.Errorf("failed to retrieve ActiveDirectoryConfig, error: %v", err)
func GetActiveDirectoryConfig(client dynamic.Interface, coreClient v1.CoreV1Interface) (*v32.ActiveDirectoryConfig, *x509.CertPool, error) {
var gvr = schema.GroupVersionResource{
Group: "management.cattle.io",
Version: "v3",
Resource: "authconfigs",
}

u, err := unstructured.ToUnstructured(authConfigObj)
authConfigObj, err := client.Resource(gvr).Get(context.TODO(), ActiveDirectoryAuth, metav1.GetOptions{})
if err != nil {
return nil, nil, fmt.Errorf("failed to retrieve openldap config, cannot read k8s Unstructured data")
return nil, nil, fmt.Errorf("failed to retrieve openldap config, error: %v", err)
}
storedADConfigMap := u.UnstructuredContent()
storedADConfigMap := authConfigObj.UnstructuredContent()

storedADConfig := &v32.ActiveDirectoryConfig{}
mapstructure.Decode(storedADConfigMap, storedADConfig)
Expand Down
2 changes: 1 addition & 1 deletion tool/ldap.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (l *LDAPAuthTool) NewAuthTool(management managementv3.Interface, coreClient
l.management = management
l.coreClient = coreClient
l.client = client
ldapConfig, caPool, err := GetLDAPConfig(l.client, coreClient)
ldapConfig, caPool, err := GetLDAPConfig(l.client, l.coreClient)
if err != nil {
return err
}
Expand Down

0 comments on commit 6d016d0

Please sign in to comment.