Skip to content

Commit

Permalink
Merge pull request #384 from lbbniu/feature/lbbniu/namespace
Browse files Browse the repository at this point in the history
Make crane's namespace configurable
  • Loading branch information
qmhu authored Jun 30, 2022
2 parents 0a9ee39 + a8f0fdd commit fb918ce
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
4 changes: 4 additions & 0 deletions deploy/craned/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ spec:
env:
- name: TZ
value: Asia/Shanghai
- name: CRANE_SYSTEM_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
command:
- /craned
- --prometheus-address=PROMETHEUS_ADDRESS
Expand Down
8 changes: 4 additions & 4 deletions pkg/controller/analytics/analytics_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
unstructuredv1 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand Down Expand Up @@ -329,7 +329,7 @@ func (c *Controller) getIdentities(ctx context.Context, analytics *analysisv1alp
}
gvr := gv.WithResource(resName)

var unstructureds []unstructured.Unstructured
var unstructureds []unstructuredv1.Unstructured

if rs.Name != "" {
unstructured, err := c.dynamicClient.Resource(gvr).Namespace(analytics.Namespace).Get(ctx, rs.Name, metav1.GetOptions{})
Expand All @@ -338,7 +338,7 @@ func (c *Controller) getIdentities(ctx context.Context, analytics *analysisv1alp
}
unstructureds = append(unstructureds, *unstructured)
} else {
var unstructuredList *unstructured.UnstructuredList
var unstructuredList *unstructuredv1.UnstructuredList
var err error

if analytics.Namespace == known.CraneSystemNamespace {
Expand All @@ -352,7 +352,7 @@ func (c *Controller) getIdentities(ctx context.Context, analytics *analysisv1alp

for _, item := range unstructuredList.Items {
// todo: rename rs.LabelSelector to rs.matchLabelSelector ?
m, ok, err := unstructured.NestedStringMap(item.Object, "spec", "selector", "matchLabels")
m, ok, err := unstructuredv1.NestedStringMap(item.Object, "spec", "selector", "matchLabels")
if !ok || err != nil {
return nil, fmt.Errorf("%s not supported", gvr.String())
}
Expand Down
4 changes: 0 additions & 4 deletions pkg/known/const.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package known

const (
CraneSystemNamespace = "crane-system"
)

const (
MetricNamePodCpuUsage = "crane_pod_cpu_usage"
)
Expand Down
13 changes: 13 additions & 0 deletions pkg/known/vars.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package known

import "os"

var (
CraneSystemNamespace = "crane-system"
)

func init() {
if namespace, ok := os.LookupEnv("CRANE_SYSTEM_NAMESPACE"); ok {
CraneSystemNamespace = namespace
}
}

0 comments on commit fb918ce

Please sign in to comment.