Skip to content

Commit d832db1

Browse files
authored
feat(main): add apis node (#57)
Signed-off-by: cuisongliu <[email protected]>
1 parent 11e5b41 commit d832db1

File tree

7 files changed

+379
-92
lines changed

7 files changed

+379
-92
lines changed

.github/workflows/test.yml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
uses: codecov/codecov-action@v4
2929
with:
3030
token: ${{ secrets.CODECOV_TOKEN }}
31-
job2:
31+
job1:
3232
runs-on: ubuntu-20.04
3333
steps:
3434
- name: Checkout
@@ -48,9 +48,16 @@ jobs:
4848
cd deploy
4949
sudo sealos build -t ghcr.io/${{ github.repository_owner }}/automq-operator-sealos:latest .
5050
51-
job1:
51+
job2:
5252
runs-on: ubuntu-20.04
5353
steps:
54+
- name: Before freeing up disk space
55+
run: |
56+
echo "Before freeing up disk space"
57+
echo "=============================================================================="
58+
df -hT
59+
echo "=============================================================================="
60+
5461
- name: Checkout
5562
uses: actions/checkout@master
5663

@@ -62,7 +69,7 @@ jobs:
6269
- name: Verify sealos
6370
run: |
6471
curl -sfL https://raw.githubusercontent.com/labring/sealos/v5.0.0/scripts/install.sh | sh -s v5.0.0 labring/sealos
65-
- name: prune os
72+
- name: install k8s and apps
6673
run: |
6774
sudo systemctl unmask containerd
6875
sudo systemctl unmask docker
@@ -74,7 +81,10 @@ jobs:
7481
sudo rm -rf /run/containerd/containerd.sock
7582
sudo sealos run labring/kubernetes:v1.27.7
7683
sudo sealos run labring/helm:v3.9.4 labring/calico:v3.26.5 labring/openebs:v3.9.0 labring/cert-manager:v1.14.6
77-
sudo sealos run labring/minio:RELEASE.2024-01-11T07-46-16Z labring/kube-prometheus-stack:v0.63.0 labring/kafka-ui:v0.7.1
84+
sudo sealos run labring/minio:RELEASE.2024-01-11T07-46-16Z labring/kube-prometheus-stack:v0.63.0
85+
sudo sealos run labring/kafka-ui:v0.7.1
86+
sleep 10
87+
sudo kubectl get pods -A --show-labels
7888
- name: build
7989
run: |
8090
sudo make e2e

cmd/main.go

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,13 @@ package main
1818

1919
import (
2020
"flag"
21-
v1 "k8s.io/api/core/v1"
2221
"os"
23-
"sigs.k8s.io/controller-runtime/pkg/client"
24-
2522
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
2623
// to ensure that exec-entrypoint and run can make use of them.
2724
_ "k8s.io/client-go/plugin/pkg/client/auth"
2825

2926
infrav1beta1 "github.com/cuisongliu/automq-operator/api/v1beta1"
3027
"github.com/cuisongliu/automq-operator/internal/controller"
31-
"github.com/gin-gonic/gin"
3228
promv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
3329
"k8s.io/apimachinery/pkg/runtime"
3430
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
@@ -130,30 +126,7 @@ func main() {
130126

131127
go func() {
132128
if mgr.GetCache().WaitForCacheSync(ctx) {
133-
setupLog.Info("cache sync success")
134-
router := gin.Default()
135-
router.GET("/api/v1/nodes/:name", func(c *gin.Context) {
136-
name := c.Param("name")
137-
node := &v1.Node{}
138-
node.Name = name
139-
if noe := mgr.GetClient().Get(ctx, client.ObjectKeyFromObject(node), node); noe != nil {
140-
c.JSON(500, gin.H{"message": noe.Error()})
141-
return
142-
}
143-
nodeIP := ""
144-
for _, addr := range node.Status.Addresses {
145-
if addr.Type == v1.NodeInternalIP {
146-
nodeIP = addr.Address
147-
break
148-
}
149-
}
150-
if nodeIP == "" {
151-
c.JSON(500, gin.H{"message": "node ip not found"})
152-
return
153-
}
154-
c.String(200, nodeIP)
155-
})
156-
router.Run(":9090")
129+
controller.APIRegistry(ctx, mgr.GetClient())
157130
}
158131
}()
159132

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
Copyright 2024 [email protected].
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package e2e
18+
19+
import (
20+
"context"
21+
"os"
22+
"time"
23+
24+
infrav1beta1 "github.com/cuisongliu/automq-operator/api/v1beta1"
25+
. "github.com/onsi/ginkgo/v2"
26+
. "github.com/onsi/gomega"
27+
v1 "k8s.io/api/core/v1"
28+
"k8s.io/apimachinery/pkg/api/errors"
29+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
30+
"sigs.k8s.io/controller-runtime/pkg/client"
31+
)
32+
33+
var _ = Describe("automq_controller", func() {
34+
Context("automq_controller cr tests", func() {
35+
ctx := context.Background()
36+
namespaceName := "automq-operator"
37+
namespace := &v1.Namespace{
38+
ObjectMeta: metav1.ObjectMeta{
39+
Name: namespaceName,
40+
Namespace: namespaceName,
41+
},
42+
}
43+
automq := &infrav1beta1.AutoMQ{}
44+
automq.Name = "automq-s1"
45+
automq.Namespace = namespaceName
46+
automq.Spec.ClusterID = "rZdE0DjZSrqy96PXrMUZVw"
47+
48+
BeforeEach(func() {
49+
By("Creating the Namespace to perform the tests")
50+
err := k8sClient.Create(ctx, namespace)
51+
Expect(err).To(Not(HaveOccurred()))
52+
By("Setting the NAMESPACE_NAME ENV VAR which stores the Operand image")
53+
err = os.Setenv("NAMESPACE_NAME", namespaceName)
54+
Expect(err).To(Not(HaveOccurred()))
55+
})
56+
It("Update Endpoint", func() {
57+
By("creating the custom resource for the automq")
58+
err := k8sClient.Get(ctx, client.ObjectKeyFromObject(automq), automq)
59+
if err != nil && errors.IsNotFound(err) {
60+
// Let's mock our custom resource at the same way that we would
61+
// apply on the cluster the manifest under config/samples
62+
automq.Spec.S3.Endpoint = "http://minio.minio.svc.cluster.local:9000"
63+
automq.Spec.S3.Bucket = "ko3"
64+
automq.Spec.S3.AccessKeyID = "admin"
65+
automq.Spec.S3.SecretAccessKey = "minio123"
66+
automq.Spec.S3.Region = "us-east-1"
67+
automq.Spec.S3.EnablePathStyle = true
68+
automq.Spec.Controller.Replicas = 1
69+
automq.Spec.Broker.Replicas = 3
70+
automq.Spec.NodePort = 32009
71+
err = k8sClient.Create(ctx, automq)
72+
Expect(err).To(Not(HaveOccurred()))
73+
}
74+
})
75+
AfterEach(func() {
76+
By("removing the custom resource for the automq")
77+
found := &infrav1beta1.AutoMQ{}
78+
err := k8sClient.Get(ctx, client.ObjectKeyFromObject(automq), found)
79+
Expect(err).To(Not(HaveOccurred()))
80+
81+
Eventually(func() error {
82+
return k8sClient.Delete(context.TODO(), found)
83+
}, 2*time.Minute, time.Second).Should(Succeed())
84+
85+
// TODO(user): Attention if you improve this code by adding other context test you MUST
86+
// be aware of the current delete namespace limitations.
87+
// More info: https://book.kubebuilder.io/reference/envtest.html#testing-considerations
88+
By("Deleting the Namespace to perform the tests")
89+
_ = k8sClient.Delete(ctx, namespace)
90+
91+
By("Removing the Image ENV VAR which stores the Operand image")
92+
_ = os.Unsetenv("NAMESPACE_NAME")
93+
})
94+
})
95+
96+
})

0 commit comments

Comments
 (0)