Skip to content

Add Marketplace apis #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,19 @@
# api
Contains the API definitions used by OLM and Marketplace
Contains the API definitions used by [OLM](olm) and [Marketplace](marketplace).

## Marketplace APIs

* `CatalogSourceConfig`: CatalogSourceConfigs are used to enable an operator present in the OperatorSource to your cluster. Behind the scenes, it will configure an OLM CatalogSource so that the operator can then be managed by OLM.
* `OperatorSource`: OperatorSources are used to define the external datastore we are using to store operator bundles.

### Generating deepcopy functions
The generate deepcopy functions can be updated after changing Marketpalce APIs by running the following command with version v0.10.0 of the [Operator-SDK](operator-sdk):
```bash
$ operator-sdk generate k8s
```

[operator-sdk]: https://github.com/operator-framework/operator-sdk/

[marketplace]: https://github.com/operator-framework/operator-marketplace/

[olm]: https://github.com/operator-framework/operator-lifecycle-manager/
15 changes: 15 additions & 0 deletions build/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM registry.access.redhat.com/ubi7/ubi-minimal:latest

ENV OPERATOR=/usr/local/bin/api2 \
USER_UID=1001 \
USER_NAME=api2

# install operator binary
COPY build/_output/bin/api2 ${OPERATOR}

COPY build/bin /usr/local/bin
RUN /usr/local/bin/user_setup

ENTRYPOINT ["/usr/local/bin/entrypoint"]

USER ${USER_UID}
Binary file added build/_output/bin/client-gen
Binary file not shown.
Binary file added build/_output/bin/deepcopy-gen
Binary file not shown.
Binary file added build/_output/bin/informer-gen
Binary file not shown.
Binary file added build/_output/bin/lister-gen
Binary file not shown.
12 changes: 12 additions & 0 deletions build/bin/entrypoint
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh -e

# This is documented here:
# https://docs.openshift.com/container-platform/3.11/creating_images/guidelines.html#openshift-specific-guidelines

if ! whoami &>/dev/null; then
if [ -w /etc/passwd ]; then
echo "${USER_NAME:-api2}:x:$(id -u):$(id -g):${USER_NAME:-api2} user:${HOME}:/sbin/nologin" >> /etc/passwd
fi
fi

exec ${OPERATOR} $@
13 changes: 13 additions & 0 deletions build/bin/user_setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh
set -x

# ensure $HOME exists and is accessible by group 0 (we don't know what the runtime UID will be)
mkdir -p ${HOME}
chown ${USER_UID}:0 ${HOME}
chmod ug+rwx ${HOME}

# runtime user will need to be able to self-insert in /etc/passwd
chmod g+rw /etc/passwd

# no need for this script to remain in the image after running
rm $0
9 changes: 9 additions & 0 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package main

import (
"log"
)

func main() {
log.Print("The Operator-SDK requires that this file exists.")
}
30 changes: 30 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Generated with the following commands:
// Version v0.10.0 of the Operator-SDK: $ operator-sdk print-deps --as-file
// $ go mod tidy
module github.com/operator-framework/api

// Pinned to kubernetes-1.13.4
replace (
k8s.io/api => k8s.io/api v0.0.0-20190222213804-5cb15d344471
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.0.0-20190228180357-d002e88f6236
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20190221213512-86fb29eff628
k8s.io/client-go => k8s.io/client-go v0.0.0-20190228174230-b40b2a5939e4
)

replace (
github.com/coreos/prometheus-operator => github.com/coreos/prometheus-operator v0.29.0
// Pinned to v2.9.2 (kubernetes-1.13.1) so https://proxy.golang.org can
// resolve it correctly.
github.com/prometheus/prometheus => github.com/prometheus/prometheus v0.0.0-20190424153033-d3245f150225
k8s.io/kube-state-metrics => k8s.io/kube-state-metrics v1.6.0
sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.1.12
sigs.k8s.io/controller-tools => sigs.k8s.io/controller-tools v0.1.11-0.20190411181648-9d55346c2bde
)

replace github.com/operator-framework/operator-sdk => github.com/operator-framework/operator-sdk v0.10.0

require (
github.com/operator-framework/operator-sdk v0.0.0-00010101000000-000000000000
k8s.io/apimachinery v0.0.0-20190612125636-6a5db36e93ad
sigs.k8s.io/controller-runtime v0.1.10
)
484 changes: 484 additions & 0 deletions go.sum

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions pkg/apis/operators/shared/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Package shared contains structs used by various API groups
// +k8s:deepcopy-gen=package,register
// +groupName=operators.coreos.com
package shared
9 changes: 9 additions & 0 deletions pkg/apis/operators/shared/phase.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package shared

// NewPhase returns a Phase object with the given name and message
func NewPhase(name string, message string) *Phase {
return &Phase{
Name: name,
Message: message,
}
}
27 changes: 27 additions & 0 deletions pkg/apis/operators/shared/phase_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package shared

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// Phase describes the phase the object is in
type Phase struct {
// Name of the phase
Name string `json:"name,omitempty"`

// A human readable message indicating why the object is in this phase
Message string `json:"message,omitempty"`
}

// ObjectPhase describes the phase of a Marketplace object is in along with the
// last time a phase transition occurred and when the object was last updated
type ObjectPhase struct {
// Current phase of the object
Phase `json:"phase,omitempty"`

// Last time the object has transitioned from one phase to another
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`

// Last time the status of the object was updated
LastUpdateTime metav1.Time `json:"lastUpdateTime,omitempty"`
}
53 changes: 53 additions & 0 deletions pkg/apis/operators/shared/shared.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package shared

import (
"github.com/operator-framework/operator-sdk/pkg/k8sutil"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EnsureFinalizer ensures that the object's finalizer is included
// in the ObjectMeta Finalizers slice. If it already exists, no state change occurs.
// If it doesn't, the finalizer is appended to the slice.
func EnsureFinalizer(objectMeta *metav1.ObjectMeta, expectedFinalizer string) {
// First check if the finalizer is already included in the object.
for _, finalizer := range objectMeta.Finalizers {
if finalizer == expectedFinalizer {
return
}
}

// If it doesn't exist, append the finalizer to the object meta.
objectMeta.Finalizers = append(objectMeta.Finalizers, expectedFinalizer)

return
}

// RemoveFinalizer removes the finalizer from the object's ObjectMeta.
func RemoveFinalizer(objectMeta *metav1.ObjectMeta, deletingFinalizer string) {
outFinalizers := make([]string, 0)
for _, finalizer := range objectMeta.Finalizers {
if finalizer == deletingFinalizer {
continue
}
outFinalizers = append(outFinalizers, finalizer)
}

objectMeta.Finalizers = outFinalizers

return
}

// IsObjectInOtherNamespace returns true if the namespace is not the watched
// namespace of the operator. An false, error will be returned if there was an
// error getting the watched namespace.
func IsObjectInOtherNamespace(namespace string) (bool, error) {
watchNamespace, err := k8sutil.GetWatchNamespace()
if err != nil {
return false, err
}

if namespace != watchNamespace {
return true, nil
}
return false, nil
}
40 changes: 40 additions & 0 deletions pkg/apis/operators/shared/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions pkg/apis/operators/v1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Package v1 contains API Schema definitions for the marketplace v1 API group
// +k8s:deepcopy-gen=package,register
// +groupName=operators.coreos.com
package v1
Loading