Skip to content

Commit 14a70b8

Browse files
authored
Merge pull request #14 from Bowenislandsong/resolvingCycDependency
Removing olm dependency
2 parents 7dce4b2 + 7e77008 commit 14a70b8

35 files changed

+9736
-220
lines changed

go.mod

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,12 @@ replace (
3030
require (
3131
github.com/blang/semver v3.5.1+incompatible
3232
github.com/ghodss/yaml v1.0.0
33-
github.com/golang/groupcache v0.0.0-20191027212112-611e8accdfc9 // indirect
34-
github.com/hashicorp/golang-lru v0.5.3 // indirect
35-
github.com/operator-framework/operator-lifecycle-manager v0.0.0-20191115003340-16619cd27fa5
3633
github.com/operator-framework/operator-registry v1.5.3
3734
github.com/pkg/errors v0.8.1
3835
github.com/sirupsen/logrus v1.4.2
3936
github.com/spf13/cobra v0.0.5
4037
github.com/stretchr/testify v1.4.0
38+
k8s.io/api v0.0.0
4139
k8s.io/apiextensions-apiserver v0.0.0
4240
k8s.io/apimachinery v0.0.0
4341
k8s.io/client-go v8.0.0+incompatible

go.sum

Lines changed: 5 additions & 214 deletions
Large diffs are not rendered by default.

pkg/internal/bundle.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"encoding/json"
55

66
"github.com/blang/semver"
7-
operatorsv1alpha1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
7+
operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
88
"github.com/operator-framework/operator-registry/pkg/registry"
99
"github.com/operator-framework/operator-registry/pkg/sqlite"
1010
"github.com/pkg/errors"

pkg/lib/version/version.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package version
2+
3+
import (
4+
"encoding/json"
5+
6+
"github.com/blang/semver"
7+
)
8+
9+
// +k8s:openapi-gen=true
10+
// OperatorVersion is a wrapper around semver.Version which supports correct
11+
// marshaling to YAML and JSON.
12+
// +kubebuilder:validation:Type=string
13+
type OperatorVersion struct {
14+
semver.Version `json:"-"`
15+
}
16+
17+
// DeepCopyInto creates a deep-copy of the Version value.
18+
func (v *OperatorVersion) DeepCopyInto(out *OperatorVersion) {
19+
out.Major = v.Major
20+
out.Minor = v.Minor
21+
out.Patch = v.Patch
22+
23+
if v.Pre != nil {
24+
pre := make([]semver.PRVersion, len(v.Pre))
25+
copy(pre, v.Pre)
26+
out.Pre = pre
27+
}
28+
29+
if v.Build != nil {
30+
build := make([]string, len(v.Build))
31+
copy(build, v.Build)
32+
out.Build = build
33+
}
34+
}
35+
36+
// MarshalJSON implements the encoding/json.Marshaler interface.
37+
func (v OperatorVersion) MarshalJSON() ([]byte, error) {
38+
return json.Marshal(v.String())
39+
}
40+
41+
// UnmarshalJSON implements the encoding/json.Unmarshaler interface.
42+
func (v *OperatorVersion) UnmarshalJSON(data []byte) (err error) {
43+
var versionString string
44+
45+
if err = json.Unmarshal(data, &versionString); err != nil {
46+
return
47+
}
48+
49+
version := semver.Version{}
50+
version, err = semver.ParseTolerant(versionString)
51+
if err != nil {
52+
return err
53+
}
54+
v.Version = version
55+
return
56+
}
57+
58+
// OpenAPISchemaType is used by the kube-openapi generator when constructing
59+
// the OpenAPI spec of this type.
60+
//
61+
// See: https://github.com/kubernetes/kube-openapi/tree/master/pkg/generators
62+
func (_ OperatorVersion) OpenAPISchemaType() []string { return []string{"string"} }
63+
64+
// OpenAPISchemaFormat is used by the kube-openapi generator when constructing
65+
// the OpenAPI spec of this type.
66+
// "semver" is not a standard openapi format but tooling may use the value regardless
67+
func (_ OperatorVersion) OpenAPISchemaFormat() string { return "semver" }

pkg/lib/version/version_test.go

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package version
2+
3+
import (
4+
"encoding/json"
5+
"testing"
6+
7+
"github.com/blang/semver"
8+
"github.com/stretchr/testify/require"
9+
)
10+
11+
func TestOperatorVersionMarshal(t *testing.T) {
12+
tests := []struct {
13+
name string
14+
in OperatorVersion
15+
out []byte
16+
err error
17+
}{
18+
{
19+
name: "MMP",
20+
in: OperatorVersion{semver.MustParse("1.2.3")},
21+
out: []byte(`"1.2.3"`),
22+
},
23+
{
24+
name: "empty",
25+
in: OperatorVersion{semver.Version{}},
26+
out: []byte(`"0.0.0"`),
27+
},
28+
{
29+
name: "with-timestamp",
30+
in: OperatorVersion{semver.MustParse("1.2.3-1556715351")},
31+
out: []byte(`"1.2.3-1556715351"`),
32+
},
33+
}
34+
for _, tt := range tests {
35+
t.Run(tt.name, func(t *testing.T) {
36+
m, err := tt.in.MarshalJSON()
37+
require.Equal(t, tt.out, m, string(m))
38+
require.Equal(t, tt.err, err)
39+
})
40+
}
41+
}
42+
43+
func TestOperatorVersionUnmarshal(t *testing.T) {
44+
type TestStruct struct {
45+
Version OperatorVersion `json:"v"`
46+
}
47+
tests := []struct {
48+
name string
49+
in []byte
50+
out TestStruct
51+
err error
52+
}{
53+
{
54+
name: "MMP",
55+
in: []byte(`{"v": "1.2.3"}`),
56+
out: TestStruct{Version: OperatorVersion{semver.MustParse("1.2.3")}},
57+
},
58+
{
59+
name: "empty",
60+
in: []byte(`{"v": "0.0.0"}`),
61+
out: TestStruct{Version: OperatorVersion{semver.Version{Major: 0, Minor: 0, Patch: 0}}},
62+
},
63+
{
64+
name: "with-timestamp",
65+
in: []byte(`{"v": "1.2.3-1556715351"}`),
66+
out: TestStruct{OperatorVersion{semver.MustParse("1.2.3-1556715351")}},
67+
},
68+
}
69+
for _, tt := range tests {
70+
t.Run(tt.name, func(t *testing.T) {
71+
s := TestStruct{}
72+
err := json.Unmarshal(tt.in, &s)
73+
require.Equal(t, tt.out, s)
74+
require.Equal(t, tt.err, err)
75+
})
76+
}
77+
}
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
package operators
2+
3+
import (
4+
"fmt"
5+
6+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
7+
"k8s.io/apimachinery/pkg/types"
8+
)
9+
10+
// CatalogSourceKind is the PascalCase name of a CatalogSource's kind.
11+
const CatalogSourceKind = "CatalogSource"
12+
13+
// SourceType indicates the type of backing store for a CatalogSource
14+
type SourceType string
15+
16+
const (
17+
// SourceTypeInternal (deprecated) specifies a CatalogSource of type SourceTypeConfigmap
18+
SourceTypeInternal SourceType = "internal"
19+
20+
// SourceTypeConfigmap specifies a CatalogSource that generates a configmap-server registry
21+
SourceTypeConfigmap SourceType = "configmap"
22+
23+
// SourceTypeGrpc specifies a CatalogSource that can use an operator registry image to generate a
24+
// registry-server or connect to a pre-existing registry at an address.
25+
SourceTypeGrpc SourceType = "grpc"
26+
)
27+
28+
type CatalogSourceSpec struct {
29+
// SourceType is the type of source
30+
SourceType SourceType
31+
32+
// ConfigMap is the name of the ConfigMap to be used to back a configmap-server registry.
33+
// Only used when SourceType = SourceTypeConfigmap or SourceTypeInternal.
34+
// +Optional
35+
ConfigMap string
36+
37+
// Address is a host that OLM can use to connect to a pre-existing registry.
38+
// Format: <registry-host or ip>:<port>
39+
// Only used when SourceType = SourceTypeGrpc.
40+
// Ignored when the Image field is set.
41+
// +Optional
42+
Address string
43+
44+
// Image is an operator-registry container image to instantiate a registry-server with.
45+
// Only used when SourceType = SourceTypeGrpc.
46+
// If present, the address field is ignored.
47+
// +Optional
48+
Image string
49+
50+
// UpdateStrategy defines how updated catalog source images can be discovered
51+
// Consists of an interval that defines polling duration and an embedded strategy type
52+
// +Optional
53+
UpdateStrategy *UpdateStrategy
54+
55+
// Secrets represent set of secrets that can be used to access the contents of the catalog.
56+
// It is best to keep this list small, since each will need to be tried for every catalog entry.
57+
// +Optional
58+
Secrets []string
59+
60+
// Metadata
61+
DisplayName string
62+
Description string
63+
Publisher string
64+
Icon Icon
65+
}
66+
67+
// UpdateStrategy holds all the different types of catalog source update strategies
68+
// Currently only registry polling strategy is implemented
69+
type UpdateStrategy struct {
70+
*RegistryPoll
71+
}
72+
73+
type RegistryPoll struct {
74+
// Interval is used to determine the time interval between checks of the latest catalog source version.
75+
// The catalog operator polls to see if a new version of the catalog source is available.
76+
// If available, the latest image is pulled and gRPC traffic is directed to the latest catalog source.
77+
Interval *metav1.Duration
78+
}
79+
80+
type RegistryServiceStatus struct {
81+
Protocol string
82+
ServiceName string
83+
ServiceNamespace string
84+
Port string
85+
CreatedAt metav1.Time
86+
}
87+
88+
type GRPCConnectionState struct {
89+
Address string
90+
LastObservedState string
91+
LastConnectTime metav1.Time
92+
}
93+
94+
func (s *RegistryServiceStatus) Address() string {
95+
return fmt.Sprintf("%s.%s.svc:%s", s.ServiceName, s.ServiceNamespace, s.Port)
96+
}
97+
98+
type CatalogSourceStatus struct {
99+
Message string `json:"message,omitempty"`
100+
Reason ConditionReason `json:"reason,omitempty"`
101+
ConfigMapResource *ConfigMapResourceReference
102+
RegistryServiceStatus *RegistryServiceStatus
103+
GRPCConnectionState *GRPCConnectionState
104+
LatestImageRegistryPoll *metav1.Time
105+
}
106+
107+
type ConfigMapResourceReference struct {
108+
Name string
109+
Namespace string
110+
UID types.UID
111+
ResourceVersion string
112+
LastUpdateTime metav1.Time
113+
}
114+
115+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
116+
// +genclient
117+
118+
// CatalogSource is a repository of CSVs, CRDs, and operator packages.
119+
type CatalogSource struct {
120+
metav1.TypeMeta
121+
metav1.ObjectMeta
122+
123+
Spec CatalogSourceSpec
124+
Status CatalogSourceStatus
125+
}
126+
127+
func (c *CatalogSource) Address() string {
128+
if c.Spec.Address != "" {
129+
return c.Spec.Address
130+
}
131+
return c.Status.RegistryServiceStatus.Address()
132+
}
133+
134+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
135+
136+
// CatalogSourceList is a list of CatalogSource resources.
137+
type CatalogSourceList struct {
138+
metav1.TypeMeta
139+
metav1.ListMeta
140+
141+
Items []CatalogSource
142+
}

0 commit comments

Comments
 (0)