Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 1826724: Fix openshift_etcd_operator_build_info metric #311

Merged
merged 3 commits into from
Apr 22, 2020
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.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
17 changes: 8 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,18 @@ require (
github.com/ghodss/yaml v1.0.0
github.com/gorilla/mux v0.0.0-20191024121256-f395758b854c
github.com/jteeuwen/go-bindata v3.0.8-0.20151023091102-a0ff2567cfb7+incompatible
github.com/openshift/api v0.0.0-20200210091934-a0e53e94816b
github.com/openshift/api v0.0.0-20200326160804-ecb9283fe820
github.com/openshift/build-machinery-go v0.0.0-20200211121458-5e3d6e570160
github.com/openshift/client-go v0.0.0-20200116152001-92a2713fa240
github.com/openshift/library-go v0.0.0-20200318085456-5071c92bad8c
github.com/prometheus/client_golang v1.1.0
github.com/openshift/client-go v0.0.0-20200326155132-2a6cd50aedd0
github.com/openshift/library-go v0.0.0-20200422120251-a5cb46356745
github.com/spf13/cobra v0.0.5
github.com/spf13/pflag v1.0.5
github.com/vincent-petithory/dataurl v0.0.0-20191104211930-d1553a71de50
go.etcd.io/etcd v0.0.0-20200401174654-e694b7bb0875
google.golang.org/grpc v1.23.1
k8s.io/api v0.17.2
k8s.io/apimachinery v0.17.2
k8s.io/client-go v0.17.1
k8s.io/component-base v0.17.1
google.golang.org/grpc v1.26.0
k8s.io/api v0.18.0
k8s.io/apimachinery v0.18.0
k8s.io/client-go v0.18.0
k8s.io/component-base v0.18.0
k8s.io/klog v1.0.0
)
128 changes: 63 additions & 65 deletions go.sum

Large diffs are not rendered by default.

27 changes: 15 additions & 12 deletions pkg/cmd/mount/mount.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mount

import (
"context"
"fmt"
"io"
"io/ioutil"
Expand Down Expand Up @@ -35,16 +36,18 @@ func NewMountCommand(errOut io.Writer) *cobra.Command {
Short: "Mount a secret with certs",
Long: "This command mounts the secret with valid certs signed by etcd-cert-signer-controller",
Run: func(cmd *cobra.Command, args []string) {
must := func(fn func() error) {
if err := fn(); err != nil {
if cmd.HasParent() {
klog.Fatal(err)
}
fmt.Fprint(mountSecretOpts.errOut, err.Error())
if err := mountSecretOpts.validateMountSecretOpts(); err != nil {
if cmd.HasParent() {
klog.Fatal(err)
}
fmt.Fprint(mountSecretOpts.errOut, err.Error())
}
if err := mountSecretOpts.Run(context.TODO()); err != nil {
if cmd.HasParent() {
klog.Fatal(err)
}
fmt.Fprint(mountSecretOpts.errOut, err.Error())
}
must(mountSecretOpts.validateMountSecretOpts)
must(mountSecretOpts.Run)
},
}

Expand All @@ -57,8 +60,8 @@ func (m *mountSecretOpts) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&m.assetsDir, "assetsdir", "", "Directory location to store signed certs")
}

func (m *mountSecretOpts) Run() error {
return m.mountSecret()
func (m *mountSecretOpts) Run(ctx context.Context) error {
return m.mountSecret(ctx)
}

func (m *mountSecretOpts) validateMountSecretOpts() error {
Expand All @@ -76,7 +79,7 @@ func (m *mountSecretOpts) validateMountSecretOpts() error {
// <profile>-<podFQDN>, where profile can be peer, server
// and metric and mount the certs as commonname.crt/commonname.key
// this will run as init container in etcd pod managed by CEO.
func (m *mountSecretOpts) mountSecret() error {
func (m *mountSecretOpts) mountSecret(ctx context.Context) error {
var err error
inClusterConfig, err := rest.InClusterConfig()
if err != nil {
Expand All @@ -92,7 +95,7 @@ func (m *mountSecretOpts) mountSecret() error {
var s *v1.Secret
// wait forever for success and retry every duration interval
err = wait.PollInfinite(duration, func() (bool, error) {
s, err = client.CoreV1().Secrets("openshift-etcd").Get(getSecretName(m.commonName), metav1.GetOptions{})
s, err = client.CoreV1().Secrets("openshift-etcd").Get(ctx, getSecretName(m.commonName), metav1.GetOptions{})
if err != nil {
klog.Errorf("error in getting secret %s/%s: %v", "openshift-etcd", getSecretName(m.commonName), err)
return false, err
Expand Down
28 changes: 15 additions & 13 deletions pkg/cmd/staticpodcontroller/staticpodcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ import (
"os"
"time"

operatorv1 "github.com/openshift/api/operator/v1"
ceoapi "github.com/openshift/cluster-etcd-operator/pkg/operator/api"
"github.com/openshift/cluster-etcd-operator/pkg/version"
"github.com/openshift/library-go/pkg/operator/events"
"github.com/openshift/library-go/pkg/operator/genericoperatorclient"
"github.com/openshift/library-go/pkg/operator/v1helpers"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/vincent-petithory/dataurl"
Expand All @@ -32,6 +26,14 @@ import (
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/util/workqueue"
"k8s.io/klog"

operatorv1 "github.com/openshift/api/operator/v1"
"github.com/openshift/library-go/pkg/operator/events"
"github.com/openshift/library-go/pkg/operator/genericoperatorclient"
"github.com/openshift/library-go/pkg/operator/v1helpers"

ceoapi "github.com/openshift/cluster-etcd-operator/pkg/operator/api"
"github.com/openshift/cluster-etcd-operator/pkg/version"
)

const (
Expand Down Expand Up @@ -178,12 +180,12 @@ func NewStaticPodController(
return c
}

func (c *StaticPodController) sync() error {
func (c *StaticPodController) sync(ctx context.Context) error {
operatorSpec, _, _, err := c.operatorClient.GetOperatorState()
if err != nil {
return err
}
pod, err := c.clientset.CoreV1().Pods(etcdNamespace).Get(c.localEtcdName, metav1.GetOptions{})
pod, err := c.clientset.CoreV1().Pods(etcdNamespace).Get(ctx, c.localEtcdName, metav1.GetOptions{})
if err != nil {
klog.Infof("No Pod found in %s with name %s", etcdNamespace, c.localEtcdName)
return err
Expand All @@ -203,7 +205,7 @@ func (c *StaticPodController) sync() error {

if c.IsMemberRemove(operatorSpec, c.localEtcdName) {
klog.Infof("%s is pending removal", c.localEtcdName)
etcdMember, err := c.getMachineConfigData(staticPodPath, "master")
etcdMember, err := c.getMachineConfigData(ctx, staticPodPath, "master")
if err != nil {
klog.Warningf("etcdMember failed %v", err)
return err
Expand Down Expand Up @@ -328,7 +330,7 @@ func (c *StaticPodController) processNextWorkItem() bool {
}
defer c.queue.Done(dsKey)

err := c.sync()
err := c.sync(context.TODO())
if err == nil {
c.queue.Forget(dsKey)
return true
Expand All @@ -349,9 +351,9 @@ func (c *StaticPodController) eventHandler() cache.ResourceEventHandler {
}
}

func (c *StaticPodController) getMachineConfigData(desiredPath string, pool string) ([]byte, error) {
func (c *StaticPodController) getMachineConfigData(ctx context.Context, desiredPath string, pool string) ([]byte, error) {
mcpClient := c.dynamicClient.Resource(schema.GroupVersionResource{Group: "machineconfiguration.openshift.io", Version: "v1", Resource: "machineconfigpools"})
unstructuredMCP, err := mcpClient.Get(pool, metav1.GetOptions{})
unstructuredMCP, err := mcpClient.Get(ctx, pool, metav1.GetOptions{})
if err != nil {
return nil, err
}
Expand All @@ -365,7 +367,7 @@ func (c *StaticPodController) getMachineConfigData(desiredPath string, pool stri
klog.Infof("rendered master MachineConfig found %s\n", machineConfigName)

mcClient := c.dynamicClient.Resource(schema.GroupVersionResource{Group: "machineconfiguration.openshift.io", Version: "v1", Resource: "machineconfigs"})
unstructuredMC, err := mcClient.Get(machineConfigName, metav1.GetOptions{})
unstructuredMC, err := mcClient.Get(ctx, machineConfigName, metav1.GetOptions{})
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package clustermembercontroller

import (
"context"
"reflect"

"github.com/openshift/cluster-etcd-operator/pkg/etcdcli"
"go.etcd.io/etcd/etcdserver/etcdserverpb"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/kubernetes"
"reflect"

"testing"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes/fake"
corev1lister "k8s.io/client-go/listers/core/v1"
"testing"
)

type fakePodLister struct {
Expand All @@ -20,7 +23,7 @@ type fakePodLister struct {
}

func (f *fakePodLister) List(selector labels.Selector) (ret []*corev1.Pod, err error) {
pods, err := f.client.CoreV1().Pods(f.namespace).List(metav1.ListOptions{LabelSelector: selector.String()})
pods, err := f.client.CoreV1().Pods(f.namespace).List(context.TODO(), metav1.ListOptions{LabelSelector: selector.String()})
if err != nil {
return nil, err
}
Expand Down
39 changes: 20 additions & 19 deletions pkg/operator/hostendpointscontroller2/host_endpoints_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,11 @@ import (
"sort"
"time"

"k8s.io/apimachinery/pkg/util/mergepatch"

operatorv1 "github.com/openshift/api/operator/v1"
"github.com/openshift/cluster-etcd-operator/pkg/operator/operatorclient"
"github.com/openshift/library-go/pkg/operator/events"
"github.com/openshift/library-go/pkg/operator/resource/resourceapply"
"github.com/openshift/library-go/pkg/operator/resource/resourcemerge"
"github.com/openshift/library-go/pkg/operator/v1helpers"
operatorv1helpers "github.com/openshift/library-go/pkg/operator/v1helpers"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/util/mergepatch"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/kubernetes"
Expand All @@ -28,6 +20,15 @@ import (
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/util/workqueue"
"k8s.io/klog"

operatorv1 "github.com/openshift/api/operator/v1"
"github.com/openshift/library-go/pkg/operator/events"
"github.com/openshift/library-go/pkg/operator/resource/resourceapply"
"github.com/openshift/library-go/pkg/operator/resource/resourcemerge"
"github.com/openshift/library-go/pkg/operator/v1helpers"
operatorv1helpers "github.com/openshift/library-go/pkg/operator/v1helpers"

"github.com/openshift/cluster-etcd-operator/pkg/operator/operatorclient"
)

const (
Expand Down Expand Up @@ -78,8 +79,8 @@ func NewHostEndpoints2Controller(
return c
}

func (c *HostEndpoints2Controller) sync() error {
err := c.syncHostEndpoints2()
func (c *HostEndpoints2Controller) sync(ctx context.Context) error {
err := c.syncHostEndpoints2(ctx)

if err != nil {
_, _, updateErr := v1helpers.UpdateStatus(c.operatorClient, v1helpers.UpdateConditionFn(operatorv1.OperatorCondition{
Expand All @@ -106,7 +107,7 @@ func (c *HostEndpoints2Controller) sync() error {
return nil
}

func (c *HostEndpoints2Controller) syncHostEndpoints2() error {
func (c *HostEndpoints2Controller) syncHostEndpoints2(ctx context.Context) error {
required := hostEndpointsAsset()

// create endpoint addresses for each node
Expand Down Expand Up @@ -138,12 +139,12 @@ func (c *HostEndpoints2Controller) syncHostEndpoints2() error {
return fmt.Errorf("no master nodes are present")
}

return c.applyEndpoints(required)
return c.applyEndpoints(ctx, required)
}

func hostEndpointsAsset() *corev1.Endpoints {
return &corev1.Endpoints{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: "host-etcd-2",
Namespace: operatorclient.TargetNamespace,
},
Expand All @@ -161,10 +162,10 @@ func hostEndpointsAsset() *corev1.Endpoints {
}
}

func (c *HostEndpoints2Controller) applyEndpoints(required *corev1.Endpoints) error {
func (c *HostEndpoints2Controller) applyEndpoints(ctx context.Context, required *corev1.Endpoints) error {
existing, err := c.endpointsLister.Endpoints(operatorclient.TargetNamespace).Get("host-etcd-2")
if errors.IsNotFound(err) {
_, err := c.endpointsClient.Endpoints(operatorclient.TargetNamespace).Create(required)
_, err := c.endpointsClient.Endpoints(operatorclient.TargetNamespace).Create(ctx, required, metav1.CreateOptions{})
if err != nil {
c.eventRecorder.Warningf("EndpointsCreateFailed", "Failed to create endpoints/%s -n %s: %v", required.Name, required.Namespace, err)
return err
Expand Down Expand Up @@ -192,7 +193,7 @@ func (c *HostEndpoints2Controller) applyEndpoints(required *corev1.Endpoints) er
if klog.V(4) {
klog.Infof("Endpoints %q changes: %v", required.Namespace+"/"+required.Name, jsonPatch)
}
updated, err := c.endpointsClient.Endpoints(operatorclient.TargetNamespace).Update(toWrite)
updated, err := c.endpointsClient.Endpoints(operatorclient.TargetNamespace).Update(ctx, toWrite, metav1.UpdateOptions{})
if err != nil {
c.eventRecorder.Warningf("EndpointsUpdateFailed", "Failed to update endpoints/%s -n %s: %v", required.Name, required.Namespace, err)
return err
Expand Down Expand Up @@ -274,7 +275,7 @@ func (c *HostEndpoints2Controller) processNextWorkItem() bool {
}
defer c.queue.Done(dsKey)

err := c.sync()
err := c.sync(context.TODO())
if err == nil {
c.queue.Forget(dsKey)
return true
Expand Down
29 changes: 16 additions & 13 deletions pkg/operator/starter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,26 @@ import (
"os"
"time"

"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"

configv1 "github.com/openshift/api/config/v1"
operatorv1 "github.com/openshift/api/operator/v1"
configv1client "github.com/openshift/client-go/config/clientset/versioned"
configv1informers "github.com/openshift/client-go/config/informers/externalversions"
operatorversionedclient "github.com/openshift/client-go/operator/clientset/versioned"
operatorv1informers "github.com/openshift/client-go/operator/informers/externalversions"
"github.com/openshift/library-go/pkg/controller/controllercmd"
"github.com/openshift/library-go/pkg/operator/genericoperatorclient"
"github.com/openshift/library-go/pkg/operator/resource/resourceapply"
"github.com/openshift/library-go/pkg/operator/staticpod"
"github.com/openshift/library-go/pkg/operator/staticpod/controller/revision"
"github.com/openshift/library-go/pkg/operator/staticresourcecontroller"
"github.com/openshift/library-go/pkg/operator/status"
"github.com/openshift/library-go/pkg/operator/unsupportedconfigoverridescontroller"
"github.com/openshift/library-go/pkg/operator/v1helpers"

"github.com/openshift/cluster-etcd-operator/pkg/etcdcli"
"github.com/openshift/cluster-etcd-operator/pkg/etcdenvvar"
"github.com/openshift/cluster-etcd-operator/pkg/operator/bootstrapteardown"
Expand All @@ -25,18 +39,6 @@ import (
"github.com/openshift/cluster-etcd-operator/pkg/operator/resourcesynccontroller"
"github.com/openshift/cluster-etcd-operator/pkg/operator/scriptcontroller"
"github.com/openshift/cluster-etcd-operator/pkg/operator/targetconfigcontroller"
"github.com/openshift/library-go/pkg/controller/controllercmd"
"github.com/openshift/library-go/pkg/operator/genericoperatorclient"
"github.com/openshift/library-go/pkg/operator/resource/resourceapply"
"github.com/openshift/library-go/pkg/operator/staticpod"
"github.com/openshift/library-go/pkg/operator/staticpod/controller/revision"
"github.com/openshift/library-go/pkg/operator/staticresourcecontroller"
"github.com/openshift/library-go/pkg/operator/status"
"github.com/openshift/library-go/pkg/operator/unsupportedconfigoverridescontroller"
"github.com/openshift/library-go/pkg/operator/v1helpers"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
)

func RunOperator(ctx context.Context, controllerContext *controllercmd.ControllerContext) error {
Expand Down Expand Up @@ -104,6 +106,7 @@ func RunOperator(ctx context.Context, controllerContext *controllercmd.Controlle
[]string{
"etcd/ns.yaml",
"etcd/sa.yaml",
"etcd/svc.yaml",
},
(&resourceapply.ClientHolder{}).WithKubernetes(kubeClient),
operatorClient,
Expand Down Expand Up @@ -133,7 +136,7 @@ func RunOperator(ctx context.Context, controllerContext *controllercmd.Controlle
)

versionRecorder := status.NewVersionGetter()
clusterOperator, err := configClient.ConfigV1().ClusterOperators().Get("etcd", metav1.GetOptions{})
clusterOperator, err := configClient.ConfigV1().ClusterOperators().Get(ctx, "etcd", metav1.GetOptions{})
if err != nil && !errors.IsNotFound(err) {
return err
}
Expand Down