forked from TencentBlueKing/bk-bcs
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: bcs容器访问db授权. issue TencentBlueKing#308
- Loading branch information
1 parent
7ec9acc
commit 806ae90
Showing
24 changed files
with
1,202 additions
and
87 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,58 @@ | ||
/* | ||
* Tencent is pleased to support the open source community by making Blueking Container Service available. | ||
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. | ||
* Licensed under the MIT License (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* http://opensource.org/licenses/MIT | ||
* 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 app | ||
|
||
import ( | ||
"reflect" | ||
|
||
"bk-bcs/bcs-common/common/blog" | ||
bcsv2 "bk-bcs/bcs-services/bcs-webhook-server/pkg/apis/bk-bcs/v2" | ||
apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1" | ||
apiextensionsclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset" | ||
apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func createBcsDbPrivConfig(clientset apiextensionsclient.Interface) (bool, error) { | ||
bcsDbPrivConfigPlural := "bcsdbprivconfigs" | ||
|
||
bcsDbPrivConfigFullName := "bcsdbprivconfigs" + "." + bcsv2.SchemeGroupVersion.Group | ||
|
||
crd := &apiextensionsv1beta1.CustomResourceDefinition{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: bcsDbPrivConfigFullName, | ||
}, | ||
Spec: apiextensionsv1beta1.CustomResourceDefinitionSpec{ | ||
Group: bcsv2.SchemeGroupVersion.Group, // BcsDbPrivConfigsGroup, | ||
Version: bcsv2.SchemeGroupVersion.Version, // BcsDbPrivConfigsVersion, | ||
Scope: apiextensionsv1beta1.NamespaceScoped, | ||
Names: apiextensionsv1beta1.CustomResourceDefinitionNames{ | ||
Plural: bcsDbPrivConfigPlural, | ||
Kind: reflect.TypeOf(bcsv2.BcsDbPrivConfig{}).Name(), | ||
ListKind: reflect.TypeOf(bcsv2.BcsDbPrivConfigList{}).Name(), | ||
}, | ||
}, | ||
} | ||
|
||
_, err := clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Create(crd) | ||
if err != nil { | ||
if apierrors.IsAlreadyExists(err) { | ||
blog.Infof("crd is already exists: %s", err) | ||
return false, nil | ||
} | ||
blog.Errorf("create crd failed: %s", err) | ||
return false, err | ||
} | ||
return true, nil | ||
} |
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
46 changes: 46 additions & 0 deletions
46
bcs-services/bcs-webhook-server/pkg/apis/bk-bcs/v2/db_priv_config.go
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,46 @@ | ||
/* | ||
* Tencent is pleased to support the open source community by making Blueking Container Service available. | ||
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. | ||
* Licensed under the MIT License (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* http://opensource.org/licenses/MIT | ||
* 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 v2 | ||
|
||
import ( | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// +genclient | ||
// +genclient:noStatus | ||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object | ||
|
||
type BcsDbPrivConfig struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ObjectMeta `json:"metadata"` | ||
Spec BcsDbPrivConfigSpec `json:"spec"` | ||
} | ||
|
||
type BcsDbPrivConfigSpec struct { | ||
PodSelector map[string]string `json:"podSelector"` | ||
AppName string `json:"appName"` | ||
TargetDb string `json:"targetDb"` | ||
DbType string `json:"dbType"` | ||
CallUser string `json:"callUser"` | ||
DbName string `json:"dbName"` | ||
} | ||
|
||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object | ||
|
||
type BcsDbPrivConfigList struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ListMeta `json:"metadata"` | ||
|
||
Items []BcsDbPrivConfig `json:"items"` | ||
} |
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
83 changes: 83 additions & 0 deletions
83
bcs-services/bcs-webhook-server/pkg/apis/bk-bcs/v2/zz_generated.deepcopy.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.