Skip to content

Commit

Permalink
Removed unused labels
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Leong <alex@buoyant.io>
  • Loading branch information
adleong committed Jul 24, 2020
1 parent d6650d2 commit dc3e053
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 88 deletions.
5 changes: 0 additions & 5 deletions cli/cmd/multicluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,11 +510,6 @@ func newLinkCommand() *cobra.Command {
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("cluster-credentials-%s", opts.clusterName),
Namespace: opts.namespace,
Annotations: map[string]string{
k8s.RemoteClusterNameLabel: opts.clusterName,
k8s.RemoteClusterDomainAnnotation: configMap.Global.ClusterDomain,
k8s.RemoteClusterLinkerdNamespaceAnnotation: controlPlaneNamespace,
},
},
Data: map[string][]byte{
k8s.ConfigKeyName: kubeconfig,
Expand Down
8 changes: 1 addition & 7 deletions controller/api/destination/watcher/endpoints_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ const (
// metrics labels
service = "service"
namespace = "namespace"
targetGatewayNamespace = "target_gateway_namespace"
targetGateway = "target_gateway"
targetCluster = "target_cluster"
targetService = "target_service"
targetServiceNamespace = "target_service_namespace"
Expand Down Expand Up @@ -669,16 +667,12 @@ func metricLabels(resource interface{}) map[string]string {

labels := map[string]string{service: serviceName, namespace: ns}

gateway, hasRemoteGateway := resLabels[consts.RemoteGatewayNameLabel]
gatewayNs, hasRemoteGatwayNs := resLabels[consts.RemoteGatewayNsLabel]
remoteClusterName, hasRemoteClusterName := resLabels[consts.RemoteClusterNameLabel]
serviceFqn, hasServiceFqn := resAnnotations[consts.RemoteServiceFqName]

if hasRemoteGateway && hasRemoteGatwayNs && hasRemoteClusterName && hasServiceFqn {
if hasRemoteClusterName && hasServiceFqn {
// this means we are looking at Endpoints created for the purpose of mirroring
// an out of cluster service.
labels[targetGatewayNamespace] = gatewayNs
labels[targetGateway] = gateway
labels[targetCluster] = remoteClusterName

fqParts := strings.Split(serviceFqn, ".")
Expand Down
7 changes: 3 additions & 4 deletions controller/cmd/service-mirror/cluster_watcher_test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,10 +511,9 @@ func gateway(name, namespace, resourceVersion, ip, hostname, portName string, po
Namespace: namespace,
ResourceVersion: resourceVersion,
Annotations: map[string]string{
consts.GatewayIdentity: identity,
consts.GatewayProbePath: probePath,
consts.GatewayProbePeriod: fmt.Sprint(probePeriod),
consts.MulticlusterGatewayAnnotation: "true",
consts.GatewayIdentity: identity,
consts.GatewayProbePath: probePath,
consts.GatewayProbePeriod: fmt.Sprint(probePeriod),
},
},
Spec: corev1.ServiceSpec{
Expand Down
6 changes: 3 additions & 3 deletions controller/cmd/service-mirror/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func Main(args []string) {
}
}

func loadCredentials(link multicluster.Link, namespace string, k8sAPI *k8s.KubernetesAPI) (*servicemirror.WatchedClusterConfig, error) {
func loadCredentials(link multicluster.Link, namespace string, k8sAPI *k8s.KubernetesAPI) ([]byte, error) {
// Load the credentials secret
secret, err := k8sAPI.Interface.CoreV1().Secrets(namespace).Get(link.ClusterCredentialsSecret, metav1.GetOptions{})
if err != nil {
Expand All @@ -126,7 +126,7 @@ func loadCredentials(link multicluster.Link, namespace string, k8sAPI *k8s.Kuber
func restartClusterWatcher(
link multicluster.Link,
namespace string,
creds *servicemirror.WatchedClusterConfig,
creds []byte,
controllerK8sAPI *controllerK8s.API,
requeueLimit int,
repairPeriod time.Duration,
Expand All @@ -139,7 +139,7 @@ func restartClusterWatcher(
probeWorker.Stop()
}

cfg, err := clientcmd.RESTConfigFromKubeConfig(creds.APIConfig)
cfg, err := clientcmd.RESTConfigFromKubeConfig(creds)
if err != nil {
log.Errorf("Unable to parse kube config: %s", err)
return
Expand Down
16 changes: 8 additions & 8 deletions pkg/healthcheck/healthcheck_multicluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,15 +302,15 @@ func (hc *HealthChecker) checkRemoteClusterConnectivity() error {
continue
}

clientConfig, err := clientcmd.RESTConfigFromKubeConfig(config.APIConfig)
clientConfig, err := clientcmd.RESTConfigFromKubeConfig(config)
if err != nil {
errors = append(errors, fmt.Errorf("* secret: [%s/%s] cluster: [%s]: unable to parse api config: %s", secret.Namespace, secret.Name, config.ClusterName, err))
errors = append(errors, fmt.Errorf("* secret: [%s/%s] cluster: [%s]: unable to parse api config: %s", secret.Namespace, secret.Name, link.TargetClusterName, err))
continue
}

remoteAPI, err := k8s.NewAPIForConfig(clientConfig, "", []string{}, requestTimeout)
if err != nil {
errors = append(errors, fmt.Errorf("* secret: [%s/%s] cluster: [%s]: could not instantiate api for target cluster: %s", secret.Namespace, secret.Name, config.ClusterName, err))
errors = append(errors, fmt.Errorf("* secret: [%s/%s] cluster: [%s]: could not instantiate api for target cluster: %s", secret.Namespace, secret.Name, link.TargetClusterName, err))
continue
}

Expand All @@ -328,7 +328,7 @@ func (hc *HealthChecker) checkRemoteClusterConnectivity() error {
}

if err := comparePermissions(expectedServiceMirrorRemoteClusterPolicyVerbs, verbs); err != nil {
errors = append(errors, fmt.Errorf("* cluster: [%s]: Insufficient Service permissions: %s", config.ClusterName, err))
errors = append(errors, fmt.Errorf("* cluster: [%s]: Insufficient Service permissions: %s", link.TargetClusterName, err))
}

links = append(links, fmt.Sprintf("\t* %s", link.TargetClusterName))
Expand Down Expand Up @@ -366,15 +366,15 @@ func (hc *HealthChecker) checkRemoteClusterAnchors() error {
continue
}

clientConfig, err := clientcmd.RESTConfigFromKubeConfig(config.APIConfig)
clientConfig, err := clientcmd.RESTConfigFromKubeConfig(config)
if err != nil {
errors = append(errors, fmt.Sprintf("* secret: [%s/%s] cluster: [%s]: unable to parse api config: %s", secret.Namespace, secret.Name, config.ClusterName, err))
errors = append(errors, fmt.Sprintf("* secret: [%s/%s] cluster: [%s]: unable to parse api config: %s", secret.Namespace, secret.Name, link.TargetClusterName, err))
continue
}

remoteAPI, err := k8s.NewAPIForConfig(clientConfig, "", []string{}, requestTimeout)
if err != nil {
errors = append(errors, fmt.Sprintf("* secret: [%s/%s] cluster: [%s]: could not instantiate api for target cluster: %s", secret.Namespace, secret.Name, config.ClusterName, err))
errors = append(errors, fmt.Sprintf("* secret: [%s/%s] cluster: [%s]: could not instantiate api for target cluster: %s", secret.Namespace, secret.Name, link.TargetClusterName, err))
continue
}

Expand Down Expand Up @@ -506,7 +506,7 @@ func (hc *HealthChecker) checkIfMirrorServicesHaveEndpoints() error {
// Check if there is a relevant end-point
endpoint, err := hc.kubeAPI.CoreV1().Endpoints(svc.Namespace).Get(svc.Name, metav1.GetOptions{})
if err != nil || len(endpoint.Subsets) == 0 {
servicesWithNoEndpoints = append(servicesWithNoEndpoints, fmt.Sprintf("%s.%s mirrored from cluster [%s] (gateway: [%s/%s])", svc.Name, svc.Namespace, svc.Labels[k8s.RemoteClusterNameLabel], svc.Labels[k8s.RemoteGatewayNsLabel], svc.Labels[k8s.RemoteGatewayNameLabel]))
servicesWithNoEndpoints = append(servicesWithNoEndpoints, fmt.Sprintf("%s.%s mirrored from cluster [%s]", svc.Name, svc.Namespace, svc.Labels[k8s.RemoteClusterNameLabel]))
}
}

Expand Down
35 changes: 2 additions & 33 deletions pkg/k8s/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,52 +376,21 @@ const (
// the access information for remote clusters.
MirrorSecretType = SvcMirrorPrefix + "/remote-kubeconfig"

// DefaultExportedServiceSelector is the default label selector for exported
// services.
DefaultExportedServiceSelector = SvcMirrorPrefix + "/exported"

// RemoteGatewayNameLabel is same as GatewayNameAnnotation but on the local,
// mirrored service. It's used for quick querying when we want to figure out
// the services that are being associated with a certain gateway
RemoteGatewayNameLabel = SvcMirrorPrefix + "/remote-gateway-name"

// RemoteGatewayNsLabel follows the same kind of logic as RemoteGatewayNameLabel
RemoteGatewayNsLabel = SvcMirrorPrefix + "/remote-gateway-ns"

// MirroredResourceLabel indicates that this resource is the result
// of a mirroring operation (can be a namespace or a service)
MirroredResourceLabel = SvcMirrorPrefix + "/mirrored-service"

// MirroredGatewayLabel indicates that this is a mirrored gateway
MirroredGatewayLabel = SvcMirrorPrefix + "/mirrored-gateway"

// MirroredGatewayProbePeriod specifies the probe period for the gateway mirror
MirroredGatewayProbePeriod = SvcMirrorPrefix + "/mirrored-gateway-probe-period"

// MirroredGatewayProbePath specifies the probe path for the gateway mirror
MirroredGatewayProbePath = SvcMirrorPrefix + "/mirrored-gateway-probe-path"

// MirroredGatewayRemoteName specifies the name of the remote gateway that has been mirrored
MirroredGatewayRemoteName = SvcMirrorPrefix + "/mirrored-gateway-remote-name"

// MirroredGatewayRemoteNameSpace specifies the namespace of the remote gateway that has been mirrored
MirroredGatewayRemoteNameSpace = SvcMirrorPrefix + "/mirrored-gateway-remote-namespace"

// MulticlusterGatewayAnnotation indicates that this service is a
// gateway
MulticlusterGatewayAnnotation = SvcMirrorPrefix + "/multicluster-gateway"

// RemoteClusterNameLabel put on a local mirrored service, it
// allows us to associate a mirrored service with a remote cluster
RemoteClusterNameLabel = SvcMirrorPrefix + "/cluster-name"

// RemoteClusterDomainAnnotation is present on the secret
// carrying the config of the remote cluster, to allow for
// using custom cluster domains
RemoteClusterDomainAnnotation = SvcMirrorPrefix + "/remote-cluster-domain"

// RemoteClusterLinkerdNamespaceAnnotation is present on the secret
// carrying the config of the remote cluster
RemoteClusterLinkerdNamespaceAnnotation = SvcMirrorPrefix + "/remote-cluster-l5d-ns"

// RemoteResourceVersionAnnotation is the last observed remote resource
// version of a mirrored resource. Useful when doing updates
RemoteResourceVersionAnnotation = SvcMirrorPrefix + "/remote-resource-version"
Expand Down
30 changes: 2 additions & 28 deletions pkg/servicemirror/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,13 @@ import (
corev1 "k8s.io/api/core/v1"
)

// WatchedClusterConfig contains the needed data to identify a remote cluster
type WatchedClusterConfig struct {
APIConfig []byte
ClusterName string
ClusterDomain string
LinkerdNamespace string
}

// ParseRemoteClusterSecret extracts the credentials used to access the remote cluster
func ParseRemoteClusterSecret(secret *corev1.Secret) (*WatchedClusterConfig, error) {
clusterName, hasClusterName := secret.Annotations[consts.RemoteClusterNameLabel]
func ParseRemoteClusterSecret(secret *corev1.Secret) ([]byte, error) {
config, hasConfig := secret.Data[consts.ConfigKeyName]
domain, hasDomain := secret.Annotations[consts.RemoteClusterDomainAnnotation]
l5dNamespace, hasL5dNamespace := secret.Annotations[consts.RemoteClusterLinkerdNamespaceAnnotation]

if !hasClusterName {
return nil, fmt.Errorf("secret of type %s should contain key %s", consts.MirrorSecretType, consts.ConfigKeyName)
}
if !hasConfig {
return nil, fmt.Errorf("secret should contain target cluster name as annotation %s", consts.RemoteClusterNameLabel)
}
if !hasDomain {
return nil, fmt.Errorf("secret should contain target cluster domain as annotation %s", consts.RemoteClusterDomainAnnotation)
}

if !hasL5dNamespace {
return nil, fmt.Errorf("secret should contain target cluster linkerd installation namespace as annotation %s", consts.RemoteClusterLinkerdNamespaceAnnotation)
}

return &WatchedClusterConfig{
APIConfig: config,
ClusterName: clusterName,
ClusterDomain: domain,
LinkerdNamespace: l5dNamespace,
}, nil
return config, nil
}

0 comments on commit dc3e053

Please sign in to comment.