Skip to content

Commit df4aa3b

Browse files
committed
pkg/util/k8sutil -> pkg/k8sutil, pkg/tlsutil -> pkg/tls
1 parent 1f17426 commit df4aa3b

File tree

13 files changed

+90
-215
lines changed

13 files changed

+90
-215
lines changed

commands/operator-sdk/cmd/up/local.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ import (
3030
"github.com/operator-framework/operator-sdk/internal/util/projutil"
3131
ansibleOperator "github.com/operator-framework/operator-sdk/pkg/ansible/operator"
3232
proxy "github.com/operator-framework/operator-sdk/pkg/ansible/proxy"
33+
"github.com/operator-framework/operator-sdk/pkg/k8sutil"
3334
"github.com/operator-framework/operator-sdk/pkg/scaffold"
3435
ansibleScaffold "github.com/operator-framework/operator-sdk/pkg/scaffold/ansible"
35-
"github.com/operator-framework/operator-sdk/pkg/util/k8sutil"
3636
sdkVersion "github.com/operator-framework/operator-sdk/version"
3737

3838
"github.com/sirupsen/logrus"
File renamed without changes.

pkg/k8sutil/k8sutil.go

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// Copyright 2018 The Operator-SDK Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package k8sutil
16+
17+
import (
18+
"fmt"
19+
"os"
20+
21+
v1 "k8s.io/api/core/v1"
22+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23+
intstr "k8s.io/apimachinery/pkg/util/intstr"
24+
)
25+
26+
// GetWatchNamespace returns the namespace the operator should be watching for changes
27+
func GetWatchNamespace() (string, error) {
28+
ns, found := os.LookupEnv(WatchNamespaceEnvVar)
29+
if !found {
30+
return "", fmt.Errorf("%s must be set", WatchNamespaceEnvVar)
31+
}
32+
return ns, nil
33+
}
34+
35+
// GetOperatorName return the operator name
36+
func GetOperatorName() (string, error) {
37+
operatorName, found := os.LookupEnv(OperatorNameEnvVar)
38+
if !found {
39+
return "", fmt.Errorf("%s must be set", OperatorNameEnvVar)
40+
}
41+
if len(operatorName) == 0 {
42+
return "", fmt.Errorf("%s must not be empty", OperatorNameEnvVar)
43+
}
44+
return operatorName, nil
45+
}
46+
47+
// InitOperatorService return the static service which expose operator metrics
48+
func InitOperatorService() (*v1.Service, error) {
49+
operatorName, err := GetOperatorName()
50+
if err != nil {
51+
return nil, err
52+
}
53+
namespace, err := GetWatchNamespace()
54+
if err != nil {
55+
return nil, err
56+
}
57+
service := &v1.Service{
58+
ObjectMeta: metav1.ObjectMeta{
59+
Name: operatorName,
60+
Namespace: namespace,
61+
Labels: map[string]string{"name": operatorName},
62+
},
63+
TypeMeta: metav1.TypeMeta{
64+
Kind: "Service",
65+
APIVersion: "v1",
66+
},
67+
Spec: v1.ServiceSpec{
68+
Ports: []v1.ServicePort{
69+
{
70+
Port: PrometheusMetricsPort,
71+
Protocol: v1.ProtocolTCP,
72+
TargetPort: intstr.IntOrString{
73+
Type: intstr.String,
74+
StrVal: PrometheusMetricsPortName,
75+
},
76+
Name: PrometheusMetricsPortName,
77+
},
78+
},
79+
Selector: map[string]string{"name": operatorName},
80+
},
81+
}
82+
return service, nil
83+
}
File renamed without changes.

pkg/scaffold/cmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import (
4444
"{{ .Repo }}/pkg/apis"
4545
"{{ .Repo }}/pkg/controller"
4646
47-
k8sutil "github.com/operator-framework/operator-sdk/pkg/util/k8sutil"
47+
"github.com/operator-framework/operator-sdk/pkg/k8sutil"
4848
sdkVersion "github.com/operator-framework/operator-sdk/version"
4949
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
5050
"sigs.k8s.io/controller-runtime/pkg/client/config"

pkg/scaffold/cmd_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import (
4040
4141
"github.com/example-inc/app-operator/pkg/apis"
4242
"github.com/example-inc/app-operator/pkg/controller"
43-
k8sutil "github.com/operator-framework/operator-sdk/pkg/util/k8sutil"
43+
"github.com/operator-framework/operator-sdk/pkg/k8sutil"
4444
sdkVersion "github.com/operator-framework/operator-sdk/version"
4545
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
4646
"sigs.k8s.io/controller-runtime/pkg/client/config"

pkg/sdk/metrics.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"net/http"
2020
"strconv"
2121

22-
k8sutil "github.com/operator-framework/operator-sdk/pkg/util/k8sutil"
22+
"github.com/operator-framework/operator-sdk/pkg/k8sutil"
2323
"github.com/prometheus/client_golang/prometheus/promhttp"
2424
"github.com/sirupsen/logrus"
2525
v1 "k8s.io/api/core/v1"
File renamed without changes.

pkg/tlsutil/primitives.go renamed to pkg/tls/primitives.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func newSelfSignedCACertificate(key *rsa.PrivateKey) (*x509.Certificate, error)
8787
NotAfter: now.Add(duration365d).UTC(),
8888
KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature | x509.KeyUsageCertSign,
8989
BasicConstraintsValid: true,
90-
IsCA: true,
90+
IsCA: true,
9191
}
9292
certDERBytes, err := x509.CreateCertificate(rand.Reader, &tmpl, &tmpl, key.Public(), key)
9393
if err != nil {
File renamed without changes.

pkg/util/k8sutil/k8sutil.go

Lines changed: 0 additions & 208 deletions
This file was deleted.

test/ansible-operator/cmd/ansible-operator/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222

2323
"github.com/operator-framework/operator-sdk/pkg/ansible/operator"
2424
proxy "github.com/operator-framework/operator-sdk/pkg/ansible/proxy"
25-
"github.com/operator-framework/operator-sdk/pkg/util/k8sutil"
25+
"github.com/operator-framework/operator-sdk/pkg/k8sutil"
2626
sdkVersion "github.com/operator-framework/operator-sdk/version"
2727
"sigs.k8s.io/controller-runtime/pkg/client/config"
2828
"sigs.k8s.io/controller-runtime/pkg/manager"

test/e2e/tls_util_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"reflect"
2020
"testing"
2121

22-
"github.com/operator-framework/operator-sdk/pkg/tlsutil"
22+
tlsutil "github.com/operator-framework/operator-sdk/pkg/tls"
2323
framework "github.com/operator-framework/operator-sdk/test/e2e/framework"
2424

2525
"k8s.io/api/core/v1"

0 commit comments

Comments
 (0)