Skip to content

Commit 149a0d1

Browse files
Merge pull request #881 from njhale/sub-csh
Subscription CatalogSource Status
2 parents 5eab015 + ee71a88 commit 149a0d1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+4579
-1459
lines changed

cmd/catalog/main.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"context"
45
"flag"
56
"fmt"
67
"net/http"
@@ -14,6 +15,7 @@ import (
1415
"github.com/prometheus/client_golang/prometheus/promhttp"
1516
log "github.com/sirupsen/logrus"
1617
v1 "k8s.io/api/core/v1"
18+
utilclock "k8s.io/apimachinery/pkg/util/clock"
1719
"k8s.io/client-go/tools/clientcmd"
1820

1921
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/catalog"
@@ -66,7 +68,9 @@ func init() {
6668
}
6769

6870
func main() {
69-
stopCh := signals.SetupSignalHandler()
71+
// Get exit signal context
72+
ctx, cancel := context.WithCancel(signals.Context())
73+
defer cancel()
7074

7175
// Parse the command-line flags.
7276
flag.Parse()
@@ -91,7 +95,8 @@ func main() {
9195

9296
logger := log.New()
9397
if *debug {
94-
logger.SetLevel(log.DebugLevel)
98+
// TODO: change back to debug level
99+
logger.SetLevel(log.TraceLevel)
95100
}
96101
logger.Infof("log level %s", logger.Level)
97102

@@ -142,17 +147,17 @@ func main() {
142147
opClient := operatorclient.NewClientFromConfig(*kubeConfigPath, logger)
143148

144149
// Create a new instance of the operator.
145-
catalogOperator, err := catalog.NewOperator(*kubeConfigPath, logger, *wakeupInterval, *configmapServerImage, *catalogNamespace, namespaces...)
150+
op, err := catalog.NewOperator(ctx, *kubeConfigPath, utilclock.RealClock{}, logger, *wakeupInterval, *configmapServerImage, *catalogNamespace, namespaces...)
146151
if err != nil {
147152
log.Panicf("error configuring operator: %s", err.Error())
148153
}
149154

150-
ready, done, sync := catalogOperator.Run(stopCh)
151-
<-ready
155+
op.Run(ctx)
156+
<-op.Ready()
152157

153158
if *writeStatusName != "" {
154-
operatorstatus.MonitorClusterStatus(*writeStatusName, sync, stopCh, opClient, configClient)
159+
operatorstatus.MonitorClusterStatus(*writeStatusName, op.AtLevel(), op.Done(), opClient, configClient)
155160
}
156161

157-
<-done
162+
<-op.Done()
158163
}

cmd/olm/main.go

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"context"
45
"flag"
56
"fmt"
67
"net/http"
@@ -16,7 +17,6 @@ import (
1617
"k8s.io/client-go/tools/clientcmd"
1718

1819
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client"
19-
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/install"
2020
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/olm"
2121
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
2222
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/signals"
@@ -63,7 +63,9 @@ func init() {
6363

6464
// main function - entrypoint to OLM operator
6565
func main() {
66-
stopCh := signals.SetupSignalHandler()
66+
// Get exit signal context
67+
ctx, cancel := context.WithCancel(signals.Context())
68+
defer cancel()
6769

6870
// Parse the command-line flags.
6971
flag.Parse()
@@ -86,39 +88,14 @@ func main() {
8688
}
8789
}
8890

89-
// Create a client for OLM
90-
crClient, err := client.NewClient(*kubeConfigPath)
91-
if err != nil {
92-
log.Fatalf("error configuring client: %s", err.Error())
93-
}
94-
95-
logger := log.New()
96-
9791
// Set log level to debug if `debug` flag set
92+
logger := log.New()
9893
if *debug {
99-
logger.SetLevel(log.DebugLevel)
94+
// TODO: Switch back to debug level
95+
logger.SetLevel(log.TraceLevel)
10096
}
10197
logger.Infof("log level %s", logger.Level)
10298

103-
opClient := operatorclient.NewClientFromConfig(*kubeConfigPath, logger)
104-
105-
// create a config client for operator status
106-
config, err := clientcmd.BuildConfigFromFlags("", *kubeConfigPath)
107-
if err != nil {
108-
log.Fatalf("error configuring client: %s", err.Error())
109-
}
110-
configClient, err := configv1client.NewForConfig(config)
111-
if err != nil {
112-
log.Fatalf("error configuring client: %s", err.Error())
113-
}
114-
115-
// Create a new instance of the operator.
116-
operator, err := olm.NewOperator(logger, crClient, opClient, &install.StrategyResolver{}, *wakeupInterval, namespaces)
117-
118-
if err != nil {
119-
log.Fatalf("error configuring operator: %s", err.Error())
120-
}
121-
12299
var useTLS bool
123100
if *tlsCertPath != "" && *tlsKeyPath == "" || *tlsCertPath == "" && *tlsKeyPath != "" {
124101
logger.Warn("both --tls-key and --tls-crt must be provided for TLS to be enabled, falling back to non-https")
@@ -159,12 +136,40 @@ func main() {
159136
}()
160137
}
161138

162-
ready, done, sync := operator.Run(stopCh)
163-
<-ready
139+
// create a config client for operator status
140+
config, err := clientcmd.BuildConfigFromFlags("", *kubeConfigPath)
141+
if err != nil {
142+
log.Fatalf("error configuring client: %s", err.Error())
143+
}
144+
configClient, err := configv1client.NewForConfig(config)
145+
if err != nil {
146+
log.Fatalf("error configuring client: %s", err.Error())
147+
}
148+
opClient := operatorclient.NewClientFromConfig(*kubeConfigPath, logger)
149+
crClient, err := client.NewClient(*kubeConfigPath)
150+
if err != nil {
151+
log.Fatalf("error configuring client: %s", err.Error())
152+
}
153+
154+
// Create a new instance of the operator.
155+
op, err := olm.NewOperator(
156+
ctx,
157+
olm.WithLogger(logger),
158+
olm.WithWatchedNamespaces(namespaces...),
159+
olm.WithResyncPeriod(*wakeupInterval),
160+
olm.WithExternalClient(crClient),
161+
olm.WithOperatorClient(opClient),
162+
)
163+
if err != nil {
164+
log.Fatalf("error configuring operator: %s", err.Error())
165+
}
166+
167+
op.Run(ctx)
168+
<-op.Ready()
164169

165170
if *writeStatusName != "" {
166-
operatorstatus.MonitorClusterStatus(*writeStatusName, sync, stopCh, opClient, configClient)
171+
operatorstatus.MonitorClusterStatus(*writeStatusName, op.AtLevel(), ctx.Done(), opClient, configClient)
167172
}
168173

169-
<-done
174+
<-op.Done()
170175
}

cmd/package-server/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import (
77

88
log "github.com/sirupsen/logrus"
99
"github.com/spf13/cobra"
10-
k8sserver "k8s.io/apiserver/pkg/server"
1110
"k8s.io/apiserver/pkg/util/logs"
1211

1312
"github.com/operator-framework/operator-lifecycle-manager/pkg/package-server/server"
13+
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/signals"
1414
)
1515

1616
const (
@@ -19,13 +19,13 @@ const (
1919

2020
// config flags defined globally so that they appear on the test binary as well
2121
var (
22-
stopCh = k8sserver.SetupSignalHandler()
22+
ctx = signals.Context()
2323
options = server.NewPackageServerOptions(os.Stdout, os.Stderr)
2424
cmd = &cobra.Command{
2525
Short: "Launch a package-server",
2626
Long: "Launch a package-server",
2727
RunE: func(c *cobra.Command, args []string) error {
28-
if err := options.Run(stopCh); err != nil {
28+
if err := options.Run(ctx); err != nil {
2929
return err
3030
}
3131
return nil

pkg/api/apis/operators/clusterserviceversion_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
)
1212

1313
// ClusterServiceVersionKind is the PascalCase name of a CSV's kind.
14-
const ClusterServiceVersionKind = "ClusterServiceVersionKind"
14+
const ClusterServiceVersionKind = "ClusterServiceVersion"
1515

1616
// InstallModeType is a supported type of install mode for CSV installation
1717
type InstallModeType string

pkg/api/apis/operators/install/install.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ func Install(scheme *runtime.Scheme) {
1515
utilruntime.Must(v1alpha1.AddToScheme(scheme))
1616
utilruntime.Must(v1.AddToScheme(scheme))
1717
utilruntime.Must(scheme.SetVersionPriority(v1.SchemeGroupVersion, v1alpha1.SchemeGroupVersion))
18-
}
18+
}

pkg/api/apis/operators/reference/reference_test.go

Lines changed: 117 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import (
1111
"k8s.io/apimachinery/pkg/runtime"
1212
"k8s.io/apimachinery/pkg/types"
1313

14-
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1"
14+
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators"
15+
v1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1"
1516
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
1617
)
1718

@@ -159,6 +160,121 @@ func TestGetReference(t *testing.T) {
159160
err: nil,
160161
},
161162
},
163+
{
164+
name: "internalversion/ClusterServiceVersion",
165+
args: args{
166+
&operators.ClusterServiceVersion{
167+
ObjectMeta: metav1.ObjectMeta{
168+
Namespace: "ns",
169+
Name: "csv",
170+
UID: types.UID("uid"),
171+
SelfLink: buildSelfLink(operators.SchemeGroupVersion.String(), "clusterserviceversions", "ns", "csv"),
172+
},
173+
},
174+
},
175+
want: want{
176+
ref: &corev1.ObjectReference{
177+
Namespace: "ns",
178+
Name: "csv",
179+
UID: types.UID("uid"),
180+
Kind: operators.ClusterServiceVersionKind,
181+
APIVersion: operators.SchemeGroupVersion.String(),
182+
},
183+
err: nil,
184+
},
185+
},
186+
{
187+
name: "internalversion/InstallPlan",
188+
args: args{
189+
&v1alpha1.InstallPlan{
190+
ObjectMeta: metav1.ObjectMeta{
191+
Namespace: "ns",
192+
Name: "ip",
193+
UID: types.UID("uid"),
194+
SelfLink: buildSelfLink(operators.SchemeGroupVersion.String(), "installplans", "ns", "ip"),
195+
},
196+
},
197+
},
198+
want: want{
199+
ref: &corev1.ObjectReference{
200+
Namespace: "ns",
201+
Name: "ip",
202+
UID: types.UID("uid"),
203+
Kind: operators.InstallPlanKind,
204+
APIVersion: operators.SchemeGroupVersion.String(),
205+
},
206+
err: nil,
207+
},
208+
},
209+
{
210+
name: "internalversion/Subscription",
211+
args: args{
212+
&v1alpha1.Subscription{
213+
ObjectMeta: metav1.ObjectMeta{
214+
Namespace: "ns",
215+
Name: "sub",
216+
UID: types.UID("uid"),
217+
SelfLink: buildSelfLink(operators.SchemeGroupVersion.String(), "subscriptions", "ns", "sub"),
218+
},
219+
},
220+
},
221+
want: want{
222+
ref: &corev1.ObjectReference{
223+
Namespace: "ns",
224+
Name: "sub",
225+
UID: types.UID("uid"),
226+
Kind: operators.SubscriptionKind,
227+
APIVersion: operators.SchemeGroupVersion.String(),
228+
},
229+
err: nil,
230+
},
231+
},
232+
{
233+
name: "internalversion/CatalogSource",
234+
args: args{
235+
&v1alpha1.CatalogSource{
236+
ObjectMeta: metav1.ObjectMeta{
237+
Namespace: "ns",
238+
Name: "catsrc",
239+
UID: types.UID("uid"),
240+
SelfLink: buildSelfLink(operators.SchemeGroupVersion.String(), "catalogsources", "ns", "catsrc"),
241+
},
242+
},
243+
},
244+
want: want{
245+
ref: &corev1.ObjectReference{
246+
Namespace: "ns",
247+
Name: "catsrc",
248+
UID: types.UID("uid"),
249+
Kind: operators.CatalogSourceKind,
250+
APIVersion: operators.SchemeGroupVersion.String(),
251+
},
252+
err: nil,
253+
},
254+
},
255+
{
256+
name: "internalversion/OperatorGroup",
257+
args: args{
258+
&v1.OperatorGroup{
259+
ObjectMeta: metav1.ObjectMeta{
260+
Namespace: "ns",
261+
Name: "og",
262+
UID: types.UID("uid"),
263+
SelfLink: buildSelfLink(operators.SchemeGroupVersion.String(), "operatorgroups", "ns", "og"),
264+
},
265+
},
266+
},
267+
want: want{
268+
ref: &corev1.ObjectReference{
269+
Namespace: "ns",
270+
Name: "og",
271+
UID: types.UID("uid"),
272+
Kind: operators.OperatorGroupKind,
273+
APIVersion: operators.SchemeGroupVersion.String(),
274+
},
275+
err: nil,
276+
},
277+
},
162278
}
163279

164280
for _, tt := range tests {

pkg/api/apis/operators/register.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,7 @@ func addKnownTypes(scheme *runtime.Scheme) error {
4848
)
4949
return nil
5050
}
51+
52+
func init() {
53+
54+
}

0 commit comments

Comments
 (0)