devlopment branch (#1736)
This commit is contained in:
@@ -32,7 +32,6 @@ import (
|
||||
"k8s.io/klog"
|
||||
"kubesphere.io/kubesphere/pkg/apis/tenant/v1alpha1"
|
||||
"kubesphere.io/kubesphere/pkg/constants"
|
||||
cs "kubesphere.io/kubesphere/pkg/simple/client"
|
||||
"kubesphere.io/kubesphere/pkg/simple/client/openpitrix"
|
||||
"kubesphere.io/kubesphere/pkg/utils/k8sutil"
|
||||
"kubesphere.io/kubesphere/pkg/utils/sliceutil"
|
||||
@@ -101,7 +100,8 @@ var _ reconcile.Reconciler = &ReconcileNamespace{}
|
||||
// ReconcileNamespace reconciles a Namespace object
|
||||
type ReconcileNamespace struct {
|
||||
client.Client
|
||||
scheme *runtime.Scheme
|
||||
openpitrixClient *openpitrix.Client
|
||||
scheme *runtime.Scheme
|
||||
}
|
||||
|
||||
// Reconcile reads that state of the cluster for a Namespace object and makes changes based on the state read
|
||||
@@ -359,18 +359,9 @@ func (r *ReconcileNamespace) checkAndCreateRuntime(namespace *corev1.Namespace)
|
||||
return nil
|
||||
}
|
||||
|
||||
openPitrixClient, err := cs.ClientSets().OpenPitrix()
|
||||
|
||||
if _, notEnabled := err.(cs.ClientSetNotEnabledError); notEnabled {
|
||||
return nil
|
||||
} else if err != nil {
|
||||
klog.Error(fmt.Sprintf("create runtime, namespace: %s, error: %s", namespace.Name, err))
|
||||
return err
|
||||
}
|
||||
|
||||
adminKubeConfigName := fmt.Sprintf("kubeconfig-%s", constants.AdminUserName)
|
||||
|
||||
runtimeCredentials, err := openPitrixClient.Runtime().DescribeRuntimeCredentials(openpitrix.SystemContext(), &pb.DescribeRuntimeCredentialsRequest{SearchWord: &wrappers.StringValue{Value: adminKubeConfigName}, Limit: 1})
|
||||
runtimeCredentials, err := r.openpitrixClient.Runtime().DescribeRuntimeCredentials(openpitrix.SystemContext(), &pb.DescribeRuntimeCredentialsRequest{SearchWord: &wrappers.StringValue{Value: adminKubeConfigName}, Limit: 1})
|
||||
|
||||
if err != nil {
|
||||
klog.Error(fmt.Sprintf("create runtime, namespace: %s, error: %s", namespace.Name, err))
|
||||
@@ -391,7 +382,7 @@ func (r *ReconcileNamespace) checkAndCreateRuntime(namespace *corev1.Namespace)
|
||||
return err
|
||||
}
|
||||
|
||||
resp, err := openPitrixClient.Runtime().CreateRuntimeCredential(openpitrix.SystemContext(), &pb.CreateRuntimeCredentialRequest{
|
||||
resp, err := r.openpitrixClient.Runtime().CreateRuntimeCredential(openpitrix.SystemContext(), &pb.CreateRuntimeCredentialRequest{
|
||||
Name: &wrappers.StringValue{Value: adminKubeConfigName},
|
||||
Provider: &wrappers.StringValue{Value: "kubernetes"},
|
||||
Description: &wrappers.StringValue{Value: "kubeconfig"},
|
||||
@@ -408,7 +399,7 @@ func (r *ReconcileNamespace) checkAndCreateRuntime(namespace *corev1.Namespace)
|
||||
}
|
||||
|
||||
// TODO runtime id is invalid when recreate runtime
|
||||
runtimeId, err := openPitrixClient.Runtime().CreateRuntime(openpitrix.SystemContext(), &pb.CreateRuntimeRequest{
|
||||
runtimeId, err := r.openpitrixClient.Runtime().CreateRuntime(openpitrix.SystemContext(), &pb.CreateRuntimeRequest{
|
||||
Name: &wrappers.StringValue{Value: namespace.Name},
|
||||
RuntimeCredentialId: &wrappers.StringValue{Value: kubesphereRuntimeCredentialId},
|
||||
Provider: &wrappers.StringValue{Value: openpitrix.KubernetesProvider},
|
||||
@@ -429,17 +420,7 @@ func (r *ReconcileNamespace) checkAndCreateRuntime(namespace *corev1.Namespace)
|
||||
func (r *ReconcileNamespace) deleteRuntime(namespace *corev1.Namespace) error {
|
||||
|
||||
if runtimeId := namespace.Annotations[constants.OpenPitrixRuntimeAnnotationKey]; runtimeId != "" {
|
||||
|
||||
openPitrixClient, err := cs.ClientSets().OpenPitrix()
|
||||
|
||||
if _, notEnabled := err.(cs.ClientSetNotEnabledError); notEnabled {
|
||||
return nil
|
||||
} else if err != nil {
|
||||
klog.Errorf("delete openpitrix runtime: %s, error: %s", runtimeId, err)
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = openPitrixClient.Runtime().DeleteRuntimes(openpitrix.SystemContext(), &pb.DeleteRuntimesRequest{RuntimeId: []string{runtimeId}, Force: &wrappers.BoolValue{Value: true}})
|
||||
_, err := r.openpitrixClient.Runtime().DeleteRuntimes(openpitrix.SystemContext(), &pb.DeleteRuntimesRequest{RuntimeId: []string{runtimeId}, Force: &wrappers.BoolValue{Value: true}})
|
||||
|
||||
if err == nil || openpitrix.IsNotFound(err) || openpitrix.IsDeleted(err) {
|
||||
return nil
|
||||
|
||||
@@ -2,9 +2,6 @@ package s2ibinary
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/awserr"
|
||||
"github.com/aws/aws-sdk-go/service/s3"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||
@@ -16,7 +13,7 @@ import (
|
||||
"k8s.io/client-go/tools/record"
|
||||
"k8s.io/client-go/util/workqueue"
|
||||
"k8s.io/klog"
|
||||
"kubesphere.io/kubesphere/pkg/simple/client"
|
||||
"kubesphere.io/kubesphere/pkg/simple/client/s3"
|
||||
"kubesphere.io/kubesphere/pkg/utils/sliceutil"
|
||||
"time"
|
||||
|
||||
@@ -39,6 +36,8 @@ type S2iBinaryController struct {
|
||||
workqueue workqueue.RateLimitingInterface
|
||||
|
||||
workerLoopPeriod time.Duration
|
||||
|
||||
s3Client s3.Interface
|
||||
}
|
||||
|
||||
func NewController(devopsclientset devopsclient.Interface,
|
||||
@@ -205,29 +204,12 @@ func (c *S2iBinaryController) syncHandler(key string) error {
|
||||
}
|
||||
|
||||
func (c *S2iBinaryController) deleteBinaryInS3(s2ibin *devopsv1alpha1.S2iBinary) error {
|
||||
s3Client, err := client.ClientSets().S3()
|
||||
|
||||
key := fmt.Sprintf("%s-%s", s2ibin.Namespace, s2ibin.Name)
|
||||
err := c.s3Client.Delete(key)
|
||||
if err != nil {
|
||||
return err
|
||||
klog.Errorf("error happened while deleting %s, %v", key, err)
|
||||
}
|
||||
|
||||
input := &s3.DeleteObjectInput{
|
||||
Bucket: s3Client.Bucket(),
|
||||
Key: aws.String(fmt.Sprintf("%s-%s", s2ibin.Namespace, s2ibin.Name)),
|
||||
}
|
||||
_, err = s3Client.Client().DeleteObject(input)
|
||||
if err != nil {
|
||||
if aerr, ok := err.(awserr.Error); ok {
|
||||
switch aerr.Code() {
|
||||
case s3.ErrCodeNoSuchKey:
|
||||
return nil
|
||||
default:
|
||||
klog.Error(err, fmt.Sprintf("failed to delete s2ibin %s/%s in s3", s2ibin.Namespace, s2ibin.Name))
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
klog.Error(err, fmt.Sprintf("failed to delete s2ibin %s/%s in s3", s2ibin.Namespace, s2ibin.Name))
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -324,15 +324,6 @@ func (r *ReconcileWorkspace) deleteGroup(instance *tenantv1alpha1.Workspace) err
|
||||
}
|
||||
|
||||
func (r *ReconcileWorkspace) deleteDevOpsProjects(instance *tenantv1alpha1.Workspace) error {
|
||||
if _, err := cs.ClientSets().Devops(); err != nil {
|
||||
// skip if devops is not enabled
|
||||
if _, notEnabled := err.(cs.ClientSetNotEnabledError); notEnabled {
|
||||
return nil
|
||||
} else {
|
||||
log.Error(err, "")
|
||||
return err
|
||||
}
|
||||
}
|
||||
var wg sync.WaitGroup
|
||||
|
||||
log.Info("Delete DevOps Projects")
|
||||
|
||||
Reference in New Issue
Block a user