Skip to content

Commit

Permalink
chore: support terminal using random service name.
Browse files Browse the repository at this point in the history
Signed-off-by: yy <[email protected]>
  • Loading branch information
lingdie committed Jan 22, 2024
1 parent f3de924 commit e29ddb8
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 31 deletions.
1 change: 1 addition & 0 deletions controllers/terminal/api/v1/terminal_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type TerminalSpec struct {
// TerminalStatus defines the observed state of Terminal
type TerminalStatus struct {
AvailableReplicas int32 `json:"availableReplicas"`
ServiceName string `json:"serviceName"`
Domain string `json:"domain"`
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
# Copyright © 2023 sealos.
#
# 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.

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
Expand Down Expand Up @@ -103,9 +89,12 @@ spec:
type: integer
domain:
type: string
serviceName:
type: string
required:
- availableReplicas
- domain
- serviceName
type: object
type: object
served: true
Expand Down
2 changes: 1 addition & 1 deletion controllers/terminal/config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ kind: Kustomization
images:
- name: controller
newName: ghcr.io/labring/sealos-terminal-controller
newTag: dev
newTag: latest
14 changes: 0 additions & 14 deletions controllers/terminal/config/rbac/role.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
# Copyright © 2023 sealos.
#
# 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.

---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
Expand Down
12 changes: 10 additions & 2 deletions controllers/terminal/controllers/terminal_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package controllers

import (
"context"
"k8s.io/apimachinery/pkg/util/rand"
"os"
"time"

Expand Down Expand Up @@ -129,6 +130,13 @@ func (r *TerminalReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
return ctrl.Result{}, nil
}

if terminal.Status.ServiceName == "" {
terminal.Status.ServiceName = terminal.Name + "-svc" + rand.String(5)
if err := r.Status().Update(ctx, terminal); err != nil {
return ctrl.Result{}, err
}
}

var hostname string
if err := r.syncDeployment(ctx, terminal, &hostname); err != nil {
logger.Error(err, "create deployment failed")
Expand Down Expand Up @@ -194,7 +202,7 @@ func (r *TerminalReconciler) syncService(ctx context.Context, terminal *terminal
labelsMap := buildLabelsMap(terminal)
expectService := &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: terminal.Name,
Name: terminal.Status.ServiceName,
Namespace: terminal.Namespace,
},
Spec: corev1.ServiceSpec{
Expand All @@ -208,7 +216,7 @@ func (r *TerminalReconciler) syncService(ctx context.Context, terminal *terminal

service := &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: terminal.Name,
Name: terminal.Status.ServiceName,
Namespace: terminal.Namespace,
},
}
Expand Down
17 changes: 17 additions & 0 deletions controllers/terminal/deploy/manifests/deploy.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,12 @@ spec:
type: integer
domain:
type: string
serviceName:
type: string
required:
- availableReplicas
- domain
- serviceName
type: object
type: object
served: true
Expand Down Expand Up @@ -321,6 +324,20 @@ subjects:
apiVersion: v1
data:
controller_manager_config.yaml: |
# Copyright © 2023 sealos.
#
# 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.

apiVersion: controller-runtime.sigs.k8s.io/v1alpha1
kind: ControllerManagerConfig
health:
Expand Down

0 comments on commit e29ddb8

Please sign in to comment.