-
Notifications
You must be signed in to change notification settings - Fork 544
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #820 from njhale/sub-ip-ref
Subscription Status InstallPlan References
- Loading branch information
Showing
16 changed files
with
563 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package operators | ||
|
||
import ( | ||
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/client-go/tools/reference" | ||
) | ||
|
||
// GetReference returns an ObjectReference for a given object whose concrete value is an OLM type. | ||
func GetReference(obj runtime.Object) (*corev1.ObjectReference, error) { | ||
return reference.GetReference(scheme, obj) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
package operators | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/types" | ||
|
||
v1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1" | ||
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1" | ||
) | ||
|
||
func TestGetReference(t *testing.T) { | ||
type args struct { | ||
obj runtime.Object | ||
} | ||
type want struct { | ||
ref *corev1.ObjectReference | ||
err error | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want want | ||
}{ | ||
{ | ||
name: "Nil/Error", | ||
args: args{obj: nil}, | ||
want: want{ | ||
ref: nil, | ||
err: fmt.Errorf("can't reference a nil object"), | ||
}, | ||
}, | ||
{ | ||
name: "v1/Pod/NotRegistered/Error", | ||
args: args{&corev1.Pod{}}, | ||
want: want{ | ||
ref: nil, | ||
err: runtime.NewNotRegisteredErrForType(scheme.Name(), reflect.TypeOf(corev1.Pod{})), | ||
}, | ||
}, | ||
{ | ||
name: "v1alpha1/ClusterServiceVersion", | ||
args: args{ | ||
&v1alpha1.ClusterServiceVersion{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Namespace: "ns", | ||
Name: "csv", | ||
UID: types.UID("uid"), | ||
SelfLink: buildSelfLink(v1alpha1.SchemeGroupVersion.String(), "clusterserviceversions", "ns", "csv"), | ||
}, | ||
}, | ||
}, | ||
want: want{ | ||
ref: &corev1.ObjectReference{ | ||
Namespace: "ns", | ||
Name: "csv", | ||
UID: types.UID("uid"), | ||
Kind: v1alpha1.ClusterServiceVersionKind, | ||
APIVersion: v1alpha1.SchemeGroupVersion.String(), | ||
}, | ||
err: nil, | ||
}, | ||
}, | ||
{ | ||
name: "v1alpha1/InstallPlan", | ||
args: args{ | ||
&v1alpha1.InstallPlan{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Namespace: "ns", | ||
Name: "ip", | ||
UID: types.UID("uid"), | ||
SelfLink: buildSelfLink(v1alpha1.SchemeGroupVersion.String(), "installplans", "ns", "ip"), | ||
}, | ||
}, | ||
}, | ||
want: want{ | ||
ref: &corev1.ObjectReference{ | ||
Namespace: "ns", | ||
Name: "ip", | ||
UID: types.UID("uid"), | ||
Kind: v1alpha1.InstallPlanKind, | ||
APIVersion: v1alpha1.SchemeGroupVersion.String(), | ||
}, | ||
err: nil, | ||
}, | ||
}, | ||
{ | ||
name: "v1alpha1/Subscription", | ||
args: args{ | ||
&v1alpha1.Subscription{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Namespace: "ns", | ||
Name: "sub", | ||
UID: types.UID("uid"), | ||
SelfLink: buildSelfLink(v1alpha1.SchemeGroupVersion.String(), "subscriptions", "ns", "sub"), | ||
}, | ||
}, | ||
}, | ||
want: want{ | ||
ref: &corev1.ObjectReference{ | ||
Namespace: "ns", | ||
Name: "sub", | ||
UID: types.UID("uid"), | ||
Kind: v1alpha1.SubscriptionKind, | ||
APIVersion: v1alpha1.SchemeGroupVersion.String(), | ||
}, | ||
err: nil, | ||
}, | ||
}, | ||
{ | ||
name: "v1alpha1/CatalogSource", | ||
args: args{ | ||
&v1alpha1.CatalogSource{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Namespace: "ns", | ||
Name: "catsrc", | ||
UID: types.UID("uid"), | ||
SelfLink: buildSelfLink(v1alpha1.SchemeGroupVersion.String(), "catalogsources", "ns", "catsrc"), | ||
}, | ||
}, | ||
}, | ||
want: want{ | ||
ref: &corev1.ObjectReference{ | ||
Namespace: "ns", | ||
Name: "catsrc", | ||
UID: types.UID("uid"), | ||
Kind: v1alpha1.CatalogSourceKind, | ||
APIVersion: v1alpha1.SchemeGroupVersion.String(), | ||
}, | ||
err: nil, | ||
}, | ||
}, | ||
{ | ||
name: "v1/OperatorGroup", | ||
args: args{ | ||
&v1.OperatorGroup{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Namespace: "ns", | ||
Name: "og", | ||
UID: types.UID("uid"), | ||
SelfLink: buildSelfLink(v1.SchemeGroupVersion.String(), "operatorgroups", "ns", "og"), | ||
}, | ||
}, | ||
}, | ||
want: want{ | ||
ref: &corev1.ObjectReference{ | ||
Namespace: "ns", | ||
Name: "og", | ||
UID: types.UID("uid"), | ||
Kind: v1.OperatorGroupKind, | ||
APIVersion: v1.SchemeGroupVersion.String(), | ||
}, | ||
err: nil, | ||
}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
ref, err := GetReference(tt.args.obj) | ||
require.Equal(t, tt.want.err, err) | ||
require.Equal(t, tt.want.ref, ref) | ||
}) | ||
} | ||
} | ||
|
||
// buildSelfLink returns a selfLink. | ||
func buildSelfLink(groupVersion, plural, namespace, name string) string { | ||
if namespace == metav1.NamespaceAll { | ||
return fmt.Sprintf("/apis/%s/%s/%s", groupVersion, plural, name) | ||
} | ||
return fmt.Sprintf("/apis/%s/namespaces/%s/%s/%s", groupVersion, namespace, plural, name) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,27 @@ | ||
package operators | ||
|
||
import ( | ||
"k8s.io/apimachinery/pkg/runtime" | ||
utilruntime "k8s.io/apimachinery/pkg/util/runtime" | ||
|
||
v1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1" | ||
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1" | ||
) | ||
|
||
// GroupName is the API group name. | ||
const GroupName = "operators.coreos.com" | ||
|
||
var ( | ||
scheme = runtime.NewScheme() | ||
localSchemeBuilder = runtime.SchemeBuilder{ | ||
v1alpha1.AddToScheme, | ||
v1.AddToScheme, | ||
} | ||
|
||
// AddToScheme adds all types in the operators.coreos.com group to the given scheme. | ||
AddToScheme = localSchemeBuilder.AddToScheme | ||
) | ||
|
||
func init() { | ||
utilruntime.Must(AddToScheme(scheme)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.