Skip to content

Commit 1e0c36d

Browse files
authored
update kubeeye api (#337)
* update mod * adjust customized inspect struct * add system workspace label when create "kubeeye-system" namespace * support component rule exclude
1 parent f22b754 commit 1e0c36d

File tree

111 files changed

+220
-21192
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+220
-21192
lines changed

apis/kubeeye/v1alpha2/inspectrule_types.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,17 @@ type InspectRuleSpec struct {
2828
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
2929
// Important: Run "make" to regenerate code after modifying this file
3030

31-
PrometheusEndpoint string `json:"prometheusEndpoint,omitempty"`
32-
Opas []OpaRule `json:"opas,omitempty"`
33-
Prometheus []PrometheusRule `json:"prometheus,omitempty"`
34-
FileChange []FileChangeRule `json:"fileChange,omitempty" `
35-
Sysctl []SysRule `json:"sysctl,omitempty"`
36-
Systemd []SysRule `json:"systemd,omitempty"`
37-
FileFilter []FileFilterRule `json:"fileFilter,omitempty"`
38-
CustomCommand []CustomCommandRule `json:"customCommand,omitempty"`
39-
NodeInfo []NodeInfo `json:"nodeInfo,omitempty"`
40-
ServiceConnect []ServiceConnectRuleItem `json:"serviceConnect,omitempty"`
31+
ComponentExclude []string `json:"componentExclude,omitempty"`
32+
PrometheusEndpoint string `json:"prometheusEndpoint,omitempty"`
33+
Opas []OpaRule `json:"opas,omitempty"`
34+
Prometheus []PrometheusRule `json:"prometheus,omitempty"`
35+
FileChange []FileChangeRule `json:"fileChange,omitempty" `
36+
Sysctl []SysRule `json:"sysctl,omitempty"`
37+
Systemd []SysRule `json:"systemd,omitempty"`
38+
FileFilter []FileFilterRule `json:"fileFilter,omitempty"`
39+
CustomCommand []CustomCommandRule `json:"customCommand,omitempty"`
40+
NodeInfo []NodeInfoRule `json:"nodeInfo,omitempty"`
41+
ServiceConnect []ServiceConnectRule `json:"serviceConnect,omitempty"`
4142
}
4243
type RuleItemBases struct {
4344
Name string `json:"name,omitempty"`
@@ -46,7 +47,7 @@ type RuleItemBases struct {
4647
Level Level `json:"level,omitempty"`
4748
}
4849

49-
type ServiceConnectRuleItem struct {
50+
type ServiceConnectRule struct {
5051
RuleItemBases `json:",inline"`
5152
Namespace string `json:"namespace,omitempty"`
5253
Workspace string `json:"workspace,omitempty"`
@@ -57,7 +58,7 @@ type Node struct {
5758
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
5859
}
5960

60-
type NodeInfo struct {
61+
type NodeInfoRule struct {
6162
RuleItemBases `json:",inline"`
6263
Node `json:",inline"`
6364
ResourcesType string `json:"resourcesType,omitempty"`

apis/kubeeye/v1alpha2/zz_generated.deepcopy.go

Lines changed: 23 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/ke-manager/main.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/kubesphere/kubeeye/pkg/kube"
2121
"go.uber.org/zap/zapcore"
2222
"os"
23+
"sigs.k8s.io/controller-runtime/pkg/metrics/server"
2324

2425
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
2526
// to ensure that exec-entrypoint and run can make use of them.
@@ -70,9 +71,10 @@ func main() {
7071
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))
7172

7273
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
73-
Scheme: scheme,
74-
MetricsBindAddress: metricsAddr,
75-
Port: 9443,
74+
Scheme: scheme,
75+
Metrics: server.Options{
76+
BindAddress: metricsAddr,
77+
},
7678
HealthProbeBindAddress: probeAddr,
7779
LeaderElection: enableLeaderElection,
7880
LeaderElectionID: "fa68b2a3.kubesphere.io",

config/crd/bases/kubeeye.kubesphere.io_inspectrules.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ spec:
3939
spec:
4040
description: InspectRuleSpec defines the desired state of InspectRule
4141
properties:
42+
componentExclude:
43+
items:
44+
type: string
45+
type: array
4246
customCommand:
4347
items:
4448
properties:

deploy/kubeeye_v1alpha2_inspectplan.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ kind: InspectPlan
33
metadata:
44
name: inspectplan
55
spec:
6-
maxTasks: 10
76
ruleNames:
7+
- name: inspect-rule-systemd
88
- name: services-connect
9-
timeout: 30m
10-
9+
status: {}

pkg/constant/constant.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const (
1212
DefaultNamespace = "kubeeye-system"
1313
)
1414

15-
var SystemNamespaces = []string{"kubesphere-system", "kubesphere-logging-system", "kubesphere-monitoring-system", "openpitrix-system", "kube-system", "istio-system", "kubesphere-devops-system", "porter-system"}
15+
var SystemNamespaces = []string{"kubeeye-system", "kubesphere-system", "kubesphere-logging-system", "kubesphere-monitoring-system", "openpitrix-system", "kube-system", "istio-system", "kubesphere-devops-system", "porter-system"}
1616

1717
const BaseFilePrefix = "kubeeye-base-file"
1818
const (
@@ -60,6 +60,7 @@ const (
6060
AnnotationJoinRuleNum = "kubeeye.kubesphere.io/join-rule-num"
6161
AnnotationDescription = "kubeeye.kubesphere.io/description"
6262
AnnotationInspectType = "kubeeye.kubesphere.io/inspect-type"
63+
AnnotationInspectIgnore = "kubeeye.kubesphere.io/inspect-ignore"
6364
)
6465

6566
const (

pkg/controllers/inspectrules_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ func ComputeLevel(data interface{}, mapLevel map[kubeeyev1alpha2.Level]*int) {
163163
for _, m := range maps {
164164
v, ok := m["level"]
165165
if !ok {
166-
mapLevel[kubeeyev1alpha2.DangerLevel] = Autoincrement(kubeeyev1alpha2.DangerLevel)
166+
mapLevel[kubeeyev1alpha2.WarningLevel] = Autoincrement(kubeeyev1alpha2.WarningLevel)
167167
} else {
168168
l := v.(string)
169169
mapLevel[kubeeyev1alpha2.Level(l)] = Autoincrement(kubeeyev1alpha2.Level(l))

pkg/controllers/inspecttask_controller.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -514,9 +514,23 @@ func isTimeout(startTime metav1.Time, t string) bool {
514514
// InitClusterInspect Initialize the relevant configuration items required for multi-cluster inspection
515515
func (r *InspectTaskReconciler) initClusterInspectConfig(ctx context.Context, clients *kube.KubernetesClient) error {
516516

517-
_, err := clients.ClientSet.CoreV1().Namespaces().Create(ctx, &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: constant.DefaultNamespace}}, metav1.CreateOptions{})
518-
if err != nil && !kubeErr.IsAlreadyExists(err) {
519-
return err
517+
_, err := clients.ClientSet.CoreV1().Namespaces().Get(ctx, constant.DefaultNamespace, metav1.GetOptions{})
518+
if err != nil {
519+
if kubeErr.IsNotFound(err) {
520+
_, err = clients.ClientSet.CoreV1().Namespaces().Create(ctx, &corev1.Namespace{
521+
ObjectMeta: metav1.ObjectMeta{
522+
Name: constant.DefaultNamespace,
523+
Labels: map[string]string{"kubesphere.io/workspace": "system-workspace"},
524+
}},
525+
metav1.CreateOptions{})
526+
527+
if err != nil && !kubeErr.IsAlreadyExists(err) {
528+
return err
529+
}
530+
} else {
531+
return err
532+
}
533+
520534
}
521535

522536
_, err = clients.ClientSet.RbacV1().ClusterRoles().Create(ctx, template.GetClusterRoleTemplate(), metav1.CreateOptions{})

pkg/controllers/suite_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package controllers
1818

1919
import (
20+
"github.com/onsi/ginkgo/reporters"
2021
"path/filepath"
2122
"testing"
2223

@@ -26,7 +27,6 @@ import (
2627
"k8s.io/client-go/rest"
2728
"sigs.k8s.io/controller-runtime/pkg/client"
2829
"sigs.k8s.io/controller-runtime/pkg/envtest"
29-
"sigs.k8s.io/controller-runtime/pkg/envtest/printer"
3030
logf "sigs.k8s.io/controller-runtime/pkg/log"
3131
"sigs.k8s.io/controller-runtime/pkg/log/zap"
3232

@@ -46,7 +46,7 @@ func TestAPIs(t *testing.T) {
4646

4747
RunSpecsWithDefaultAndCustomReporters(t,
4848
"Controller Suite",
49-
[]Reporter{printer.NewlineReporter{}})
49+
[]Reporter{&reporters.JUnitReporter{}})
5050
}
5151

5252
var _ = BeforeSuite(func() {

0 commit comments

Comments
 (0)