-
Notifications
You must be signed in to change notification settings - Fork 1
/
common.go
46 lines (38 loc) · 1.31 KB
/
common.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*******************************************************************************
* Copyright (c) 2018, 2019 Red Hat Inc
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package handler
import (
"github.com/ctron/iot-simulator-console/pkg/data"
"github.com/prometheus/common/log"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func getMessageType(obj metav1.Object) string {
labels := obj.GetLabels()
return labels["iot.simulator.message.type"]
}
func (c *controller) fillCommon(tenants *map[string]*data.Tenant, obj metav1.Object, replicas int) (*data.Tenant, data.Component) {
tenantName := obj.GetLabels()["iot.simulator.tenant"]
if tenantName == "" {
return nil, data.Component{}
}
tenant := registerTenant(tenants, tenantName)
messageType := getMessageType(obj)
if messageType == "" {
log.Warn("Missing message type")
return nil, data.Component{}
}
return tenant, data.Component{
Type: messageType,
Replicas: uint32(replicas),
}
}