forked from chaos-mesh/chaos-mesh
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
multicluster: auto install and uninstall the remote helm release (cha…
…os-mesh#3414) * add remotecluster type Signed-off-by: YangKeao <[email protected]> * add the infrastructure to operate multiple clusters Signed-off-by: YangKeao <[email protected]> * remove clientset Signed-off-by: YangKeao <[email protected]> * modify changelog Signed-off-by: YangKeao <[email protected]> * add license to the remote-cluster.yaml Signed-off-by: YangKeao <[email protected]> * fix Wrapf arguments Signed-off-by: YangKeao <[email protected]> * make check Signed-off-by: YangKeao <[email protected]> * make the lock private Signed-off-by: YangKeao <[email protected]> * chore: helm chart integration and basic interface Signed-off-by: STRRL <[email protected]> * chore: complete the implementation of ReleaseService Signed-off-by: STRRL <[email protected]> * chore: update changelog Signed-off-by: STRRL <[email protected]> * install chaos mesh Signed-off-by: YangKeao <[email protected]> * add CHANGELOG Signed-off-by: YangKeao <[email protected]> * chore: helm chart integration and basic interface Signed-off-by: STRRL <[email protected]> * chore: complete the implementation of ReleaseService Signed-off-by: STRRL <[email protected]> * chore: update changelog Signed-off-by: STRRL <[email protected]> * chore: fix make check Signed-off-by: STRRL <[email protected]> * chore: update lincense checker config file Signed-off-by: STRRL <[email protected]> * test: mark examples of helm as integration test Signed-off-by: STRRL <[email protected]> * add condition initialization for remote cluster Signed-off-by: YangKeao <[email protected]> * upgrade chaosmesh release version to 2.4.1 Signed-off-by: YangKeao <[email protected]> Signed-off-by: YangKeao <[email protected]> Signed-off-by: STRRL <[email protected]> Co-authored-by: STRRL <[email protected]> Co-authored-by: Ti Chi Robot <[email protected]>
- Loading branch information
1 parent
fc1349d
commit 2617080
Showing
5 changed files
with
294 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2022 Chaos Mesh Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
package remotecluster | ||
|
||
import ( | ||
corev1 "k8s.io/api/core/v1" | ||
|
||
"github.com/chaos-mesh/chaos-mesh/api/v1alpha1" | ||
) | ||
|
||
func setRemoteClusterCondition(obj *v1alpha1.RemoteCluster, typ v1alpha1.RemoteClusterConditionType, status corev1.ConditionStatus, reason string) { | ||
conditionMap := map[v1alpha1.RemoteClusterConditionType]v1alpha1.RemoteClusterCondition{ | ||
v1alpha1.RemoteClusterConditionInstalled: {Type: v1alpha1.RemoteClusterConditionInstalled, Status: corev1.ConditionFalse}, | ||
v1alpha1.RemoteClusterConditionReady: {Type: v1alpha1.RemoteClusterConditionReady, Status: corev1.ConditionFalse}, | ||
} | ||
|
||
for _, condition := range obj.Status.Conditions { | ||
conditionMap[condition.Type] = condition | ||
} | ||
|
||
conditionMap[typ] = v1alpha1.RemoteClusterCondition{Type: typ, Status: status, Reason: reason} | ||
|
||
conditions := make([]v1alpha1.RemoteClusterCondition, 0, len(conditionMap)) | ||
for _, condition := range conditionMap { | ||
conditions = append(conditions, condition) | ||
} | ||
|
||
obj.Status.Conditions = conditions | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright 2022 Chaos Mesh Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
package remotecluster | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/gomega" | ||
corev1 "k8s.io/api/core/v1" | ||
|
||
"github.com/chaos-mesh/chaos-mesh/api/v1alpha1" | ||
) | ||
|
||
func TestSetRemoteClusterCondition(t *testing.T) { | ||
RegisterTestingT(t) | ||
|
||
obj := &v1alpha1.RemoteCluster{} | ||
setRemoteClusterCondition(obj, v1alpha1.RemoteClusterConditionInstalled, corev1.ConditionTrue, "test") | ||
|
||
Expect(len(obj.Status.Conditions)).To(Equal(2)) | ||
haveConditionInstalled := false | ||
for _, condition := range obj.Status.Conditions { | ||
if condition.Type == v1alpha1.RemoteClusterConditionInstalled { | ||
Expect(condition.Status).To(Equal(corev1.ConditionTrue)) | ||
Expect(condition.Reason).To(Equal("test")) | ||
|
||
haveConditionInstalled = true | ||
} else { | ||
Expect(condition.Status).To(Equal(corev1.ConditionFalse)) | ||
} | ||
} | ||
|
||
Expect(haveConditionInstalled).To(Equal(true)) | ||
} |
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Copyright 2022 Chaos Mesh Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
package helm | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
"k8s.io/apimachinery/pkg/api/meta" | ||
"k8s.io/cli-runtime/pkg/genericclioptions" | ||
"k8s.io/client-go/discovery" | ||
"k8s.io/client-go/discovery/cached/memory" | ||
"k8s.io/client-go/rest" | ||
"k8s.io/client-go/restmapper" | ||
"k8s.io/client-go/tools/clientcmd" | ||
) | ||
|
||
var _ genericclioptions.RESTClientGetter = &restClientGetter{} | ||
|
||
type restClientGetter struct { | ||
clientConfig clientcmd.ClientConfig | ||
} | ||
|
||
func NewRESTClientGetter(clientConfig clientcmd.ClientConfig) genericclioptions.RESTClientGetter { | ||
return &restClientGetter{ | ||
clientConfig, | ||
} | ||
} | ||
|
||
func (getter *restClientGetter) ToRESTConfig() (*rest.Config, error) { | ||
return getter.clientConfig.ClientConfig() | ||
} | ||
|
||
func (getter *restClientGetter) ToDiscoveryClient() (discovery.CachedDiscoveryInterface, error) { | ||
restConfig, err := getter.clientConfig.ClientConfig() | ||
if err != nil { | ||
return nil, errors.Wrap(err, "get rest config from client config") | ||
} | ||
|
||
client, err := discovery.NewDiscoveryClientForConfig(restConfig) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "create discovery client") | ||
} | ||
return memory.NewMemCacheClient(client), nil | ||
} | ||
|
||
func (getter *restClientGetter) ToRESTMapper() (meta.RESTMapper, error) { | ||
discoveryClient, err := getter.ToDiscoveryClient() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
mapper := restmapper.NewDeferredDiscoveryRESTMapper(discoveryClient) | ||
expander := restmapper.NewShortcutExpander(mapper, discoveryClient) | ||
return expander, nil | ||
} | ||
|
||
func (getter *restClientGetter) ToRawKubeConfigLoader() clientcmd.ClientConfig { | ||
return getter.clientConfig | ||
} |