fix generation bug (#2043)
This commit is contained in:
@@ -309,6 +309,16 @@ func (c *ClusterController) syncCluster(key string) error {
|
|||||||
cluster.Spec.Connection.KubernetesAPIEndpoint = fmt.Sprintf("https://%s:%d", service.Spec.ClusterIP, kubernetesPort)
|
cluster.Spec.Connection.KubernetesAPIEndpoint = fmt.Sprintf("https://%s:%d", service.Spec.ClusterIP, kubernetesPort)
|
||||||
cluster.Spec.Connection.KubeSphereAPIEndpoint = fmt.Sprintf("http://%s:%d", service.Spec.ClusterIP, kubespherePort)
|
cluster.Spec.Connection.KubeSphereAPIEndpoint = fmt.Sprintf("http://%s:%d", service.Spec.ClusterIP, kubespherePort)
|
||||||
|
|
||||||
|
initializedCondition := clusterv1alpha1.ClusterCondition{
|
||||||
|
Type: clusterv1alpha1.ClusterInitialized,
|
||||||
|
Status: v1.ConditionTrue,
|
||||||
|
Reason: string(clusterv1alpha1.ClusterInitialized),
|
||||||
|
Message: "Cluster has been initialized",
|
||||||
|
LastUpdateTime: metav1.Now(),
|
||||||
|
LastTransitionTime: metav1.Now(),
|
||||||
|
}
|
||||||
|
c.updateClusterCondition(cluster, initializedCondition)
|
||||||
|
|
||||||
if !reflect.DeepEqual(oldCluster.Spec, cluster.Spec) {
|
if !reflect.DeepEqual(oldCluster.Spec, cluster.Spec) {
|
||||||
cluster, err = c.clusterClient.Update(cluster)
|
cluster, err = c.clusterClient.Update(cluster)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ const (
|
|||||||
defaultAgentImage = "kubesphere/tower:v1.0"
|
defaultAgentImage = "kubesphere/tower:v1.0"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var ErrClusterConnectionIsNotProxy = fmt.Errorf("cluster is not using proxy connection")
|
||||||
|
|
||||||
type handler struct {
|
type handler struct {
|
||||||
serviceLister v1.ServiceLister
|
serviceLister v1.ServiceLister
|
||||||
clusterLister clusterlister.ClusterLister
|
clusterLister clusterlister.ClusterLister
|
||||||
@@ -62,6 +64,11 @@ func (h *handler) GenerateAgentDeployment(request *restful.Request, response *re
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if cluster.Spec.Connection.Type != v1alpha1.ConnectionTypeProxy {
|
||||||
|
api.HandleNotFound(response, request, fmt.Errorf("cluster %s is not using proxy connection", cluster.Name))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// use service ingress address
|
// use service ingress address
|
||||||
if len(h.proxyAddress) == 0 {
|
if len(h.proxyAddress) == 0 {
|
||||||
err = h.populateProxyAddress()
|
err = h.populateProxyAddress()
|
||||||
@@ -126,6 +133,10 @@ func (h *handler) populateProxyAddress() error {
|
|||||||
|
|
||||||
func (h *handler) generateDefaultDeployment(cluster *v1alpha1.Cluster, w io.Writer) error {
|
func (h *handler) generateDefaultDeployment(cluster *v1alpha1.Cluster, w io.Writer) error {
|
||||||
|
|
||||||
|
if cluster.Spec.Connection.Type == v1alpha1.ConnectionTypeDirect {
|
||||||
|
return ErrClusterConnectionIsNotProxy
|
||||||
|
}
|
||||||
|
|
||||||
agent := appsv1.Deployment{
|
agent := appsv1.Deployment{
|
||||||
TypeMeta: metav1.TypeMeta{
|
TypeMeta: metav1.TypeMeta{
|
||||||
Kind: "Deployment",
|
Kind: "Deployment",
|
||||||
|
|||||||
@@ -98,6 +98,33 @@ func TestGeranteAgentDeployment(t *testing.T) {
|
|||||||
informersFactory.KubernetesSharedInformerFactory().Core().V1().Services().Informer().GetIndexer().Add(service)
|
informersFactory.KubernetesSharedInformerFactory().Core().V1().Services().Informer().GetIndexer().Add(service)
|
||||||
informersFactory.KubeSphereSharedInformerFactory().Cluster().V1alpha1().Clusters().Informer().GetIndexer().Add(cluster)
|
informersFactory.KubeSphereSharedInformerFactory().Cluster().V1alpha1().Clusters().Informer().GetIndexer().Add(cluster)
|
||||||
|
|
||||||
|
directConnectionCluster := cluster.DeepCopy()
|
||||||
|
directConnectionCluster.Spec.Connection.Type = v1alpha1.ConnectionTypeDirect
|
||||||
|
|
||||||
|
var testCases = []struct {
|
||||||
|
description string
|
||||||
|
expectingError bool
|
||||||
|
expectedError error
|
||||||
|
cluster *v1alpha1.Cluster
|
||||||
|
expected string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
description: "test normal case",
|
||||||
|
expectingError: false,
|
||||||
|
expected: expected,
|
||||||
|
cluster: cluster,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
description: "test direct connection cluster",
|
||||||
|
expectingError: true,
|
||||||
|
expectedError: ErrClusterConnectionIsNotProxy,
|
||||||
|
cluster: directConnectionCluster,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
|
||||||
|
t.Run(testCase.description, func(t *testing.T) {
|
||||||
h := NewHandler(informersFactory.KubernetesSharedInformerFactory().Core().V1().Services().Lister(),
|
h := NewHandler(informersFactory.KubernetesSharedInformerFactory().Core().V1().Services().Lister(),
|
||||||
informersFactory.KubeSphereSharedInformerFactory().Cluster().V1alpha1().Clusters().Lister(),
|
informersFactory.KubeSphereSharedInformerFactory().Cluster().V1alpha1().Clusters().Lister(),
|
||||||
proxyService,
|
proxyService,
|
||||||
@@ -111,11 +138,18 @@ func TestGeranteAgentDeployment(t *testing.T) {
|
|||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = h.generateDefaultDeployment(cluster, &buf)
|
err = h.generateDefaultDeployment(testCase.cluster, &buf)
|
||||||
if diff := cmp.Diff(buf.String(), expected); len(diff) != 0 {
|
if testCase.expectingError {
|
||||||
t.Error(diff)
|
if err == nil {
|
||||||
|
t.Fatalf("expecting error %v, got nil", testCase.expectedError)
|
||||||
|
} else if err != testCase.expectedError {
|
||||||
|
t.Fatalf("expecting error %v, got %v", testCase.expectedError, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func TestInnerGenerateAgentDeployment(t *testing.T) {
|
func TestInnerGenerateAgentDeployment(t *testing.T) {
|
||||||
h := &handler{
|
h := &handler{
|
||||||
|
|||||||
Reference in New Issue
Block a user