Skip to content

Commit

Permalink
feat: support configure ingressClassName (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
narasux authored Feb 3, 2023
1 parent 0ddf03f commit fcbbe67
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 7 deletions.
6 changes: 1 addition & 5 deletions operator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## 部署说明

K8S 集群版本要求: **>=1.17**
K8S 集群版本要求: **>=1.19**

### 部署步骤
1. (可选) 安装 cert-manager
Expand All @@ -23,10 +23,6 @@ kubectl create ns bkpaas-app-operator-system
helm install bkpaas-app-operator paasv3/bkpaas-app-operator -n bkpaas-app-operator-system -f values.yaml
```

其中:
- paasv3/bkpaas-app-operator 维护在仓库 [helm-deploy] 项目
- values.yaml 维护在仓库 [helm-values] 项目

## 开发指南

安装 ginkgo 命令行工具:
Expand Down
2 changes: 2 additions & 0 deletions operator/api/v1alpha1/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ const (
RevisionAnnoKey = "bkapp.paas.bk.tencent.com/revision"
// ResourceTypeKey 注解中存储资源类型的键名
ResourceTypeKey = "bkapp.paas.bk.tencent.com/resource-type"
// IngressClassAnnoKey 通过该注解绑定 ingress 的控制器
IngressClassAnnoKey = "kubernetes.io/ingress.class"
)

const (
Expand Down
2 changes: 2 additions & 0 deletions operator/api/v1alpha1/projectconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ type PlatformConfig struct {
BkAPIGatewayURL string `json:"bkAPIGatewayURL"`
// sentry server dsn, all events waiting for report will be dropped if unset
SentryDSN string `json:"sentryDSN"`
// if ingressClassName configured, kubernetes.io/ingress.class=$value will be added to ingress's annotations
IngressClassName string `json:"ingressClassName"`
}

// IngressPluginConfig contains the config for controlling ingress config
Expand Down
4 changes: 4 additions & 0 deletions operator/api/v1alpha1/projectconfig_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ platformConfig:
bkAppCode: "foo"
bkAppSecret: "bar"
bkAPIGatewayURL: "https://example.com"
sentryDSN: "https://sentry.example.com"
ingressClassName: nginx
`
file, err := ioutil.TempFile("", "")
Expect(err).NotTo(HaveOccurred())
Expand All @@ -71,5 +73,7 @@ platformConfig:
Expect(projectConfig.PlatformConfig.BkAppCode).To(Equal("foo"))
Expect(projectConfig.PlatformConfig.BkAppSecret).To(Equal("bar"))
Expect(projectConfig.PlatformConfig.BkAPIGatewayURL).To(Equal("https://example.com"))
Expect(projectConfig.PlatformConfig.SentryDSN).To(Equal("https://sentry.example.com"))
Expect(projectConfig.PlatformConfig.IngressClassName).To(Equal("nginx"))
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ spec:
type: string
bkAppSecret:
type: string
ingressClassName:
description: if ingressClassName configured, kubernetes.io/ingress.class=$value
will be added to ingress's annotations
type: string
sentryDSN:
description: sentry server dsn, all events waiting for report will
be dropped if unset
Expand All @@ -179,6 +183,7 @@ spec:
- bkAPIGatewayURL
- bkAppCode
- bkAppSecret
- ingressClassName
- sentryDSN
type: object
resLimitConfig:
Expand Down
1 change: 1 addition & 0 deletions operator/config/manager/controller_manager_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ platformConfig:
bkAppSecret: ""
bkAPIGatewayURL: ""
sentryDSN: ""
ingressClassName: ""
ingressPluginConfig:
accessControlConfig:
redisConfigKey: ""
Expand Down
2 changes: 2 additions & 0 deletions operator/config/samples/paas_v1alpha1_projectconfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ platformConfig:
bkAppSecret: ""
bkAPIGatewayURL: ""
sentryDSN: ""
## when there are multiple ingress controllers in your cluster, setting the ingressClassName is necessary.
ingressClassName: ""
resLimitConfig:
procDefaultCPULimits: "4"
procDefaultMemLimits: "1Gi"
Expand Down
9 changes: 7 additions & 2 deletions operator/pkg/controllers/resources/ingresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

paasv1alpha1 "bk.tencent.com/paas-app-operator/api/v1alpha1"
"bk.tencent.com/paas-app-operator/pkg/config"
"bk.tencent.com/paas-app-operator/pkg/controllers/resources/labels"
"bk.tencent.com/paas-app-operator/pkg/controllers/resources/names"
)
Expand Down Expand Up @@ -168,7 +169,7 @@ func (builder MonoIngressBuilder) Build(domains []Domain) ([]*networkingv1.Ingre
// TODO: The resource name might conflict if multiple DomainGroupMappings uses
// same sourceTypes.
name := fmt.Sprintf("%s-%s", bkapp.Name, builder.sourceType)
val := networkingv1.Ingress{
ingress := networkingv1.Ingress{
TypeMeta: metav1.TypeMeta{APIVersion: "v1", Kind: "Ingress"},
ObjectMeta: metav1.ObjectMeta{
Name: name,
Expand All @@ -185,7 +186,11 @@ func (builder MonoIngressBuilder) Build(domains []Domain) ([]*networkingv1.Ingre
TLS: makeTLS(domains),
},
}
results = append(results, &val)
// 如果已配置 ingressClassName,则使用
if ingClassName := config.Global.PlatformConfig.IngressClassName; ingClassName != "" {
ingress.Annotations[paasv1alpha1.IngressClassAnnoKey] = ingClassName
}
results = append(results, &ingress)
return results, nil
}

Expand Down

0 comments on commit fcbbe67

Please sign in to comment.