Skip to content
This repository is currently being migrated. It's locked while the migration is in progress.

Commit 825d7de

Browse files
authored
Ability to apply licence (#63)
* Ability to apply licence * Send error status on failed licence update * Send proper status response after action execution * Verify data integrity of action * ezaz * First working prototype * Fix action config ID parsing * Fix MQTT and StorageOS connections * Fix error handling of storageos client refresh * Fix IOT core logging name * Make scripts in hack executable * Retry action, Mutex for IOT subscribe, logging polish * Fix licence report error handling * Fix message broker connection leak * Final polish * Fix docker build
1 parent faa05b5 commit 825d7de

Some content is hidden

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

67 files changed

+1676
-799
lines changed

Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ COPY endpoints/ endpoints/
1414
COPY managers/ managers/
1515
COPY pkg/ pkg/
1616
COPY vendor/ vendor/
17-
COPY watchers/ watchers/
1817

1918
# Build
2019
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -mod=vendor -a -o manager main.go

api/v1alpha1/portalconfig_types.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
Copyright 2022.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
116
package v1alpha1
217

318
import (
@@ -18,6 +33,9 @@ type IOTCoreConfig struct {
1833

1934
// SeverURL is the url of the iot server
2035
ServerURL string `json:"serverUrl,omitempty"`
36+
37+
// SignatureKey is the public part of message signature keys.
38+
SignatureKey string `json:"signatureKey,omitempty"`
2139
}
2240

2341
//+kubebuilder:object:root=true

api/v1alpha1/storageosportal_types.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
Copyright 2022.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
116
package v1alpha1
217

318
import (

config/crd/bases/storageos.com_portalconfigs.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ spec:
9292
serverUrl:
9393
description: SeverURL is the url of the iot server
9494
type: string
95+
signatureKey:
96+
description: SignatureKey is the public part of message signature
97+
keys.
98+
type: string
9599
type: object
96100
kind:
97101
description: 'Kind is a string value representing the REST resource this

controllers/config_controller.go

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
Copyright 2022.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
/*
18+
Copyright 2022.
19+
20+
Licensed under the Apache License, Version 2.0 (the "License");
21+
you may not use this file except in compliance with the License.
22+
You may obtain a copy of the License at
23+
24+
http://www.apache.org/licenses/LICENSE-2.0
25+
26+
Unless required by applicable law or agreed to in writing, software
27+
distributed under the License is distributed on an "AS IS" BASIS,
28+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29+
See the License for the specific language governing permissions and
30+
limitations under the License.
31+
*/
32+
package controllers
33+
34+
import (
35+
"context"
36+
"fmt"
37+
38+
storageosv1alpha1 "github.com/storageos/portal-manager/api/v1alpha1"
39+
corev1 "k8s.io/api/core/v1"
40+
"k8s.io/apimachinery/pkg/runtime"
41+
"k8s.io/client-go/util/workqueue"
42+
ctrl "sigs.k8s.io/controller-runtime"
43+
"sigs.k8s.io/controller-runtime/pkg/client"
44+
"sigs.k8s.io/controller-runtime/pkg/controller"
45+
"sigs.k8s.io/controller-runtime/pkg/event"
46+
"sigs.k8s.io/controller-runtime/pkg/source"
47+
)
48+
49+
// ConfigReconciler reconciles StorageOS related configs.
50+
type ConfigReconciler struct {
51+
client.Client
52+
Scheme *runtime.Scheme
53+
}
54+
55+
// Reconcile changes of watched resources.
56+
func (r *ConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
57+
return ctrl.Result{}, nil
58+
}
59+
60+
type configEventHandler struct {
61+
namespace string
62+
}
63+
64+
func (eh configEventHandler) Create(event.CreateEvent, workqueue.RateLimitingInterface) {}
65+
66+
// Update detects StorageOS related config changes.
67+
func (eh configEventHandler) Update(e event.UpdateEvent, _ workqueue.RateLimitingInterface) {
68+
if e.ObjectNew.GetNamespace() != eh.namespace {
69+
return
70+
}
71+
72+
if app, ok := e.ObjectNew.GetLabels()["app"]; !ok || app != "storageos" {
73+
return
74+
}
75+
76+
panic(fmt.Errorf("some config has changed: %s", e.ObjectNew.GetName()))
77+
}
78+
79+
func (eh configEventHandler) Delete(event.DeleteEvent, workqueue.RateLimitingInterface) {}
80+
81+
func (eh configEventHandler) Generic(event.GenericEvent, workqueue.RateLimitingInterface) {}
82+
83+
// SetupWithManager sets up the controller with the Manager.
84+
func (r *ConfigReconciler) SetupWithManager(mgr ctrl.Manager, namespace string) error {
85+
configEventHandler := configEventHandler{namespace: namespace}
86+
87+
return ctrl.NewControllerManagedBy(mgr).
88+
For(&storageosv1alpha1.StorageOSPortal{}).
89+
Watches(&source.Kind{Type: &corev1.Secret{}}, configEventHandler).
90+
Watches(&source.Kind{Type: &corev1.ConfigMap{}}, configEventHandler).
91+
WithOptions(controller.Options{
92+
MaxConcurrentReconciles: 1,
93+
}).
94+
Complete(r)
95+
}

controllers/publish_controller.go

Lines changed: 26 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
Copyright 2022.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
116
package controllers
217

318
import (
@@ -11,12 +26,9 @@ import (
1126
"k8s.io/apimachinery/pkg/runtime"
1227
"k8s.io/apimachinery/pkg/types"
1328
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
14-
"k8s.io/client-go/tools/record"
1529
"k8s.io/client-go/util/workqueue"
1630
ctrl "sigs.k8s.io/controller-runtime"
17-
"sigs.k8s.io/controller-runtime/pkg/client"
1831

19-
storageosv1alpha1 "github.com/storageos/portal-manager/api/v1alpha1"
2032
"github.com/storageos/portal-manager/pkg/handler"
2133
"github.com/storageos/portal-manager/pkg/publisher"
2234
"github.com/storageos/portal-manager/pkg/publisher/proto/portal"
@@ -36,11 +48,9 @@ type Event struct {
3648

3749
// Publisher watches a cache for changes and publishes them to an external sink.
3850
type Publisher struct {
39-
k8s client.Client
40-
scheme *runtime.Scheme
41-
queue workqueue.RateLimitingInterface
42-
recorder record.EventRecorder
43-
sink publisher.Sink
51+
scheme *runtime.Scheme
52+
queue workqueue.RateLimitingInterface
53+
sink publisher.Sink
4454

4555
tenant string
4656
cluster string
@@ -49,66 +59,26 @@ type Publisher struct {
4959
}
5060

5161
// NewPublisher returns a new Publisher.
52-
func NewPublisher(tenantID, clusterID string, privateKeyPem []byte, client client.Client, scheme *runtime.Scheme, queue workqueue.RateLimitingInterface, recorder record.EventRecorder, cfg storageosv1alpha1.PortalConfig, logger logr.Logger) (*Publisher, error) {
53-
logger = logger.WithName("publish_controller")
54-
55-
sink, err := publisher.New(clusterID, privateKeyPem, cfg, logger)
56-
if err != nil {
57-
return nil, errors.Wrap(err, "unable to initialize new publisher")
58-
}
59-
62+
func NewPublisher(tenantID, clusterID string, sink *publisher.Publisher, scheme *runtime.Scheme, queue workqueue.RateLimitingInterface, logger logr.Logger) (*Publisher, error) {
6063
return &Publisher{
61-
k8s: client,
62-
scheme: scheme,
63-
queue: queue,
64-
recorder: recorder,
65-
sink: sink,
66-
tenant: tenantID,
67-
cluster: clusterID,
68-
logger: logger,
64+
scheme: scheme,
65+
queue: queue,
66+
sink: sink,
67+
tenant: tenantID,
68+
cluster: clusterID,
69+
logger: logger.WithName("publish_controller"),
6970
}, nil
7071
}
7172

72-
// SetupWithManager registers with the controller manager.
73+
// SetupWithManager registers with the controller manager and sends initial states.
7374
//
7475
// Since this is an external controller, we don't need to register the
7576
// controller, just add it as a Runnable so that the manager can control startup
7677
// and shutdown.
7778
func (p *Publisher) SetupWithManager(mgr ctrl.Manager) error {
78-
if err := p.sink.Init(); err != nil {
79-
return errors.Wrap(err, "unable to initialize sink")
80-
}
8179
return mgr.Add(p)
8280
}
8381

84-
// // Start runs the main reconcile loop until the context is cancelled or there is
85-
// // a fatal error. It implements the controller-runtime Runnable interface so
86-
// // that it can be controlled by controller manager.
87-
// func (p *Publisher) Start(ctx context.Context) error {
88-
// for {
89-
// newEvent, quit := p.queue.Get()
90-
// if quit {
91-
// break
92-
// }
93-
// defer p.queue.Done(newEvent)
94-
// handlerEvent := newEvent.(handler.Event)
95-
// err := p.processEvent(ctx, handlerEvent)
96-
// if err == nil {
97-
// // No error, reset the ratelimit counters
98-
// p.queue.Forget(newEvent)
99-
// } else if p.queue.NumRequeues(newEvent) < maxRetries {
100-
// p.log.Error(err, "Error processing (will retry)", "key", handlerEvent.Key, "action", handlerEvent.Action)
101-
// p.queue.AddRateLimited(newEvent)
102-
// } else {
103-
// // err != nil and too many retries
104-
// p.log.Error(err, "Error processing (giving up)", "key", handlerEvent.Key, "action", handlerEvent.Action)
105-
// p.queue.Forget(newEvent)
106-
// utilruntime.HandleError(err)
107-
// }
108-
// }
109-
// return nil
110-
// }
111-
11282
// Start runs the main reconcile loop until the context is cancelled or there is
11383
// a fatal error. It implements the controller-runtime Runnable interface so
11484
// that it can be controlled by controller manager.

controllers/suite_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
Copyright 2022.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
116
package controllers
217

318
import (

controllers/watch_controller.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
Copyright 2022.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
116
package controllers
217

318
import (

0 commit comments

Comments
 (0)