mirror of
https://github.com/open-cluster-management-io/ocm.git
synced 2026-05-09 18:57:35 +00:00
Merge pull request #76 from skeeey/performance
rollback init clusername and agentname in secret
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"crypto/tls"
|
||||
"crypto/x509/pkix"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
"github.com/openshift/library-go/pkg/controller/factory"
|
||||
@@ -142,6 +143,20 @@ func (c *ClientCertForHubController) sync(ctx context.Context, syncCtx factory.S
|
||||
return nil
|
||||
}
|
||||
|
||||
// save the cluster name and agent name into secret if they are not saved yet
|
||||
newSecretConfig := map[string][]byte{}
|
||||
for k, v := range secret.Data {
|
||||
newSecretConfig[k] = v
|
||||
}
|
||||
newSecretConfig[ClusterNameFile] = []byte(c.clusterName)
|
||||
newSecretConfig[AgentNameFile] = []byte(c.agentName)
|
||||
if !reflect.DeepEqual(newSecretConfig, secret.Data) {
|
||||
secret.Data = newSecretConfig
|
||||
if err := c.saveHubKubeconfigSecret(secret); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// create a csr to request new client certificate if
|
||||
// a. there is no client certificate
|
||||
// b. client certificate exists and has less than 20% of its life remaining
|
||||
|
||||
@@ -3,6 +3,7 @@ package hubclientcert
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -10,6 +11,7 @@ import (
|
||||
|
||||
certificates "k8s.io/api/certificates/v1beta1"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/client-go/informers"
|
||||
kubefake "k8s.io/client-go/kubernetes/fake"
|
||||
@@ -47,7 +49,21 @@ func TestSync(t *testing.T) {
|
||||
t.Errorf("expected csr was created, but failed")
|
||||
}
|
||||
|
||||
testinghelpers.AssertNoActions(t, agentActions)
|
||||
expectedSecret := &corev1.Secret{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Namespace: testNamespace,
|
||||
Name: testSecretName,
|
||||
},
|
||||
Data: map[string][]byte{
|
||||
ClusterNameFile: []byte(testinghelpers.TestManagedClusterName),
|
||||
AgentNameFile: []byte(testAgentName),
|
||||
},
|
||||
}
|
||||
testinghelpers.AssertActions(t, agentActions, "create")
|
||||
actualSecret := agentActions[0].(clienttesting.CreateActionImpl).Object
|
||||
if !reflect.DeepEqual(expectedSecret, actualSecret) {
|
||||
t.Errorf("expected secret %v, but got %v", expectedSecret, actualSecret)
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user