Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions pkg/console/metrics/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package metrics

import (
"sync"

k8smetrics "k8s.io/component-base/metrics"
"k8s.io/component-base/metrics/legacyregistry"
)

type ConsoleMetrics struct {
ConsoleURL *k8smetrics.GaugeVec
}

var singleton *ConsoleMetrics
var once sync.Once

func Register() *ConsoleMetrics {
// thread safe
once.Do(func() {
singleton = &ConsoleMetrics{}

// metric: console_url{url="https://<url>"} 1
singleton.ConsoleURL = k8smetrics.NewGaugeVec(&k8smetrics.GaugeOpts{
Name: "console_url",
Help: "URL of the console exposed on the cluster",
// one label
}, []string{"url"})

legacyregistry.MustRegister(singleton.ConsoleURL)
})
return singleton
}
7 changes: 7 additions & 0 deletions pkg/console/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
operatorclientv1 "github.com/openshift/client-go/operator/clientset/versioned/typed/operator/v1"

// operator
"github.com/openshift/console-operator/pkg/console/metrics"
statushelpers "github.com/openshift/console-operator/pkg/console/status"
"github.com/openshift/console-operator/pkg/console/subresource/configmap"
"github.com/openshift/console-operator/pkg/console/subresource/deployment"
Expand Down Expand Up @@ -70,6 +71,8 @@ type consoleOperator struct {
routeClient routeclientv1.RoutesGetter
oauthClient oauthclientv1.OAuthClientsGetter
versionGetter status.VersionGetter
// metrics
consoleMetrics *metrics.ConsoleMetrics
// recorder
recorder events.Recorder
resourceSyncer resourcesynccontroller.ResourceSyncer
Expand All @@ -96,6 +99,8 @@ func NewConsoleOperator(
oauthClients oauthinformersv1.OAuthClientInformer,
// openshift managed
managedCoreV1 corev1.Interface,
// metrics
consoleMetrics *metrics.ConsoleMetrics,
// event handling
versionGetter status.VersionGetter,
recorder events.Recorder,
Expand All @@ -117,6 +122,8 @@ func NewConsoleOperator(
routeClient: routev1Client,
oauthClient: oauthv1Client,
versionGetter: versionGetter,
// metrics
consoleMetrics: consoleMetrics,
// recorder
recorder: recorder,
resourceSyncer: resourceSyncer,
Expand Down
20 changes: 2 additions & 18 deletions pkg/console/operator/sync_v400.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"fmt"
"os"

"github.com/prometheus/client_golang/prometheus"

// kube
oauthv1 "github.com/openshift/api/oauth/v1"
routev1 "github.com/openshift/api/route/v1"
Expand Down Expand Up @@ -37,19 +35,6 @@ import (
secretsub "github.com/openshift/console-operator/pkg/console/subresource/secret"
)

var (
// metric: console_url{url="https://<url>"} 1
consoleURLMetric = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "console_url",
Help: "URL of the console exposed on the cluster",
// one label
}, []string{"url"})
)

func init() {
prometheus.MustRegister(consoleURLMetric)
}

// The sync loop starts from zero and works its way through the requirements for a running console.
// If at any point something is missing, it creates/updates that piece and immediately dies.
// The next loop will pick up where they previous left off and move the process forward one step.
Expand Down Expand Up @@ -207,15 +192,14 @@ func (co *consoleOperator) sync_v400(updatedOperatorConfig *operatorv1.Console,

func (co *consoleOperator) SyncConsoleConfig(consoleConfig *configv1.Console, consoleURL string) (*configv1.Console, error) {
updated := consoleConfig.DeepCopy()

// track the URL state in prometheus before we update it
if consoleConfig.Status.ConsoleURL != consoleURL {
// not using this URL anymore
consoleURLMetric.WithLabelValues(consoleConfig.Status.ConsoleURL).Set(0)
co.consoleMetrics.ConsoleURL.WithLabelValues(consoleConfig.Status.ConsoleURL).Set(0)
}
if len(consoleURL) != 0 {
// only update to new if we have a url
consoleURLMetric.WithLabelValues(consoleURL).Set(1)
co.consoleMetrics.ConsoleURL.WithLabelValues(consoleURL).Set(1)
}

if updated.Status.ConsoleURL != consoleURL {
Expand Down
6 changes: 5 additions & 1 deletion pkg/console/starter/starter.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import (

"github.com/openshift/console-operator/pkg/console/clientwrapper"
"github.com/openshift/console-operator/pkg/console/controllers/service"
"github.com/openshift/console-operator/pkg/console/metrics"
"github.com/openshift/console-operator/pkg/console/operator"
"github.com/openshift/library-go/pkg/operator/loglevel"
)
Expand Down Expand Up @@ -150,8 +151,8 @@ func RunOperator(ctx *controllercmd.ControllerContext) error {
if err != nil {
return err
}
consoleMetrics := metrics.Register()

// TODO: rearrange these into informer,client pairs, NOT separated.
consoleOperator := operator.NewConsoleOperator(
// top level config
configClient.ConfigV1(),
Expand All @@ -174,6 +175,9 @@ func RunOperator(ctx *controllercmd.ControllerContext) error {
oauthInformers.Oauth().V1().OAuthClients(), // OAuth clients
// openshift managed
kubeInformersManagedNamespaced.Core().V1(), // Managed ConfigMaps
// metrics
// TODO: when we get to testing, we may want an interface for this
consoleMetrics,
// event handling
versionGetter,
recorder,
Expand Down
23 changes: 23 additions & 0 deletions test/e2e/framework/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/tools/clientcmd/api"
)

// GetConfig creates a *rest.Config for talking to a Kubernetes apiserver.
Expand All @@ -20,6 +21,14 @@ import (
// * In-cluster config if running in cluster
//
// * $HOME/.kube/config if exists
//
// Note that if you have done `oc login...` the `current-context` will be used.
// this means that the test will run as whatever user is currently logged in.
// kube:admin has a token, but no certs.
// - kube:admin is an oauth user, this is why it has tokens.
// system:admin has certs, but no token.
// - system:admin is a cert based user only.
// other users, your mileage may vary.
func GetConfig() (*rest.Config, error) {
// If an env variable is specified with the config location, use that
if len(os.Getenv("KUBECONFIG")) > 0 {
Expand All @@ -39,3 +48,17 @@ func GetConfig() (*rest.Config, error) {

return nil, fmt.Errorf("could not locate a kubeconfig")
}

// authn operator approach to getting config.
// choose func as needed.
// https://github.com/openshift/cluster-authentication-operator/blob/master/test/library/client.go
// NewClientConfigForTest returns a config configured to connect to the api server
func NewClientConfigForTest() (*rest.Config, error) {
loader := clientcmd.NewDefaultClientConfigLoadingRules()
clientConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loader, &clientcmd.ConfigOverrides{ClusterInfo: api.Cluster{InsecureSkipTLSVerify: true}})
config, err := clientConfig.ClientConfig()
if err == nil {
fmt.Printf("Found configuration for host %v.\n", config.Host)
}
return config, err
}
2 changes: 2 additions & 0 deletions test/e2e/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func DeleteAll(t *testing.T, client *ClientSet) {
func GetResource(client *ClientSet, resource TestingResource) (runtime.Object, error) {
var res runtime.Object
var err error

switch resource.kind {
case "ConfigMap":
res, err = client.Core.ConfigMaps(resource.namespace).Get(resource.name, metav1.GetOptions{})
Expand Down Expand Up @@ -234,6 +235,7 @@ func IsResourceUnavailable(errChan chan error, client *ClientSet, resource Testi
counter := 0
maxCount := 15
err := wait.Poll(1*time.Second, AsyncOperationTimeout, func() (stop bool, err error) {

obtainedResource, err := GetResource(client, resource)
if err == nil {
return true, fmt.Errorf("deleted console %s %s was recreated: %#v", resource.kind, resource.name, obtainedResource)
Expand Down
Loading