Skip to content
Merged
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
16 changes: 9 additions & 7 deletions api/v1/updateservice_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,10 @@ type UpdateServiceSpec struct {
// +kubebuilder:validation:Required
Replicas int32 `json:"replicas"`

// registry is the container registry to use, such as "quay.io".
// releases is the repository in which release images are tagged,
// such as quay.io/openshift-release-dev/ocp-release.
// +kubebuilder:validation:Required
Registry string `json:"registry"`

// repository is the repository to use in the Registry, such as
// "openshift-release-dev/ocp-release"
// +kubebuilder:validation:Required
Repository string `json:"repository"`
Releases string `json:"releases"`

// graphDataImage is a container image that contains the UpdateService graph
// data.
Expand All @@ -38,6 +34,12 @@ type UpdateServiceStatus struct {
// +patchStrategy=merge
// +kubebuilder:validation:Optional
Conditions []conditionsv1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"`

// policyEngineURI is the external URI which exposes the policy
// engine. Available paths from this URI include:
//
// * /api/upgrades_info/v1/graph, with the update graph recommendations.
PolicyEngineURI string `json:"policyEngineURI,optional"`
}

// Condition Types
Expand Down
49 changes: 35 additions & 14 deletions ...ator.openshift.io_updateservices_crd.yaml → ...operator.openshift.io_updateservices.yaml
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@

---
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.3.0
creationTimestamp: null
name: updateservices.updateservice.operator.openshift.io
spec:
group: updateservice.operator.openshift.io
Expand All @@ -14,7 +19,7 @@ spec:
status: {}
validation:
openAPIV3Schema:
description: UpdateService is the Schema for a UpdateService service.
description: UpdateService is the Schema for the updateservices API.
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
Expand All @@ -27,36 +32,36 @@ spec:
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
description: 'metadata is standard object metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata'
type: object
spec:
description: UpdateServiceSpec defines the desired state of UpdateService
description: spec is the desired state of the UpdateService service. The
operator will work to ensure that the desired configuration is applied
to the cluster.
properties:
graphDataImage:
description: GraphDataImage is a container image that contains the UpdateService
graph data. The data is copied to /var/lib/updateservice/graph-data.
description: graphDataImage is a container image that contains the UpdateService
graph data.
type: string
registry:
description: Registry is the container registry to use, such as "quay.io".
releases:
description: releases is the repository in which release images are
tagged, such as quay.io/openshift-release-dev/ocp-release.
type: string
replicas:
description: Replicas is the number of pods to run. When >=2, a PodDisruptionBudget
description: replicas is the number of pods to run. When >=2, a PodDisruptionBudget
will ensure that voluntary disruption leaves at least one Pod running
at all times.
format: int32
minimum: 1
type: integer
repository:
description: Repository is the repository to use in the Registry, such
as "openshift-release-dev/ocp-release"
type: string
required:
- graphDataImage
- registry
- releases
- replicas
- repository
type: object
status:
description: UpdateServiceStatus defines the observed state of UpdateService
description: status contains information about the current state of the
UpdateService service.
properties:
conditions:
description: Conditions describe the state of the UpdateService resource.
Expand Down Expand Up @@ -85,10 +90,26 @@ spec:
- type
type: object
type: array
policyEngineURI:
description: "policyEngineURI is the external URI which exposes the
policy engine. Available paths from this URI include: \n * /api/upgrades_info/v1/graph,
with the update graph recommendations."
type: string
required:
- policyEngineURI
type: object
required:
- metadata
- spec
type: object
version: v1
versions:
- name: v1
served: true
storage: true
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
2 changes: 1 addition & 1 deletion config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# since it depends on service name and namespace that are out of this kustomize package.
# It should be run by config/default
resources:
- bases/updateservice.operator.openshift.io_updateservices_crd.yaml
- bases/updateservice.operator.openshift.io_updateservices.yaml
# +kubebuilder:scaffold:crdkustomizeresource

patchesStrategicMerge:
Expand Down
94 changes: 0 additions & 94 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,6 @@ rules:
- deployments/finalizers
verbs:
- update
- apiGroups:
- updateservice.operator.openshift.io
resources:
- '*'
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- config.openshift.io
resources:
Expand Down Expand Up @@ -111,69 +99,6 @@ rules:
- patch
- update
- watch

---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
creationTimestamp: null
name: updateservice-operator
rules:
- apiGroups:
- ""
resources:
- configmaps
- endpoints
- events
- persistentvolumeclaims
- pods
- secrets
- services
- services/finalizers
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- ""
resources:
- pods
verbs:
- get
- apiGroups:
- apps
resources:
- daemonsets
- deployments
- replicasets
- statefulsets
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- apps
resources:
- deployments
- replicasets
verbs:
- get
- apiGroups:
- apps
resourceNames:
- updateservice-operator
resources:
- deployments/finalizers
verbs:
- update
- apiGroups:
- updateservice.operator.openshift.io
resources:
Expand All @@ -186,22 +111,3 @@ rules:
- patch
- update
- watch
- apiGroups:
- monitoring.coreos.com
resources:
- servicemonitors
verbs:
- create
- get
- apiGroups:
- policy
resources:
- poddisruptionbudgets
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ metadata:
name: example
spec:
replicas: 1
registry: "quay.io"
repository: "openshift-release-dev/ocp-release"
graphDataImage: "your-registry/your-repo/your-init-container"
releases: quay.io/openshift-release-dev/ocp-release
graphDataImage: your-registry/your-repo/your-init-container
18 changes: 17 additions & 1 deletion controllers/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ const (
EnvConfigHashAnnotation string = "updateservice.operator.openshift.io/env-config-hash"
)

type graphBuilderProperties struct {
Registry string
Repository string
}

const graphBuilderTOML string = `verbosity = "vvv"

[service]
Expand Down Expand Up @@ -252,12 +257,23 @@ func (k *kubeResources) newEnvConfig(instance *cv1.UpdateService) *corev1.Config
}

func (k *kubeResources) newGraphBuilderConfig(instance *cv1.UpdateService) (*corev1.ConfigMap, error) {
var registry, repository string
if segments := strings.SplitN(instance.Spec.Releases, "/", 2); len(segments) != 2 {
return nil, fmt.Errorf("failed to split %q into registry and repository components", instance.Spec.Releases)
} else {
registry = segments[0]
repository = segments[1]
}

tmpl, err := template.New("gb").Parse(graphBuilderTOML)
if err != nil {
return nil, err
}
builder := strings.Builder{}
if err = tmpl.Execute(&builder, instance.Spec); err != nil {
if err = tmpl.Execute(&builder, &graphBuilderProperties{
Registry: registry,
Repository: repository,
}); err != nil {
return nil, err
}
return &corev1.ConfigMap{
Expand Down
23 changes: 11 additions & 12 deletions controllers/updateservice_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
routev1 "github.com/openshift/api/route/v1"
cv1 "github.com/openshift/cincinnati-operator/api/v1"
"github.com/openshift/cluster-image-registry-operator/pkg/defaults"
"github.com/openshift/library-go/pkg/route/routeapihelpers"
)

var log = logf.Log.WithName("controller_updateservice")
Expand Down Expand Up @@ -122,23 +123,15 @@ type UpdateServiceReconciler struct {
operandImage string
}

// +kubebuilder:rbac:groups="",namespace="updateservice-operator",resources=pods;services;services/finalizers;endpoints;persistentvolumeclaims;events;configmaps;secrets,verbs=create;delete;get;list;patch;update;watch
// +kubebuilder:rbac:groups="apps",namespace="updateservice-operator",resources=deployments;daemonsets;replicasets;statefulsets,verbs=create;delete;get;list;patch;update;watch
// +kubebuilder:rbac:groups="monitoring.coreos.com",namespace="updateservice-operator",resources=servicemonitors,verbs=create;get
// +kubebuilder:rbac:groups="apps",namespace="updateservice-operator",resourceNames=updateservice-operator,resources=deployments/finalizers,verbs=update
// +kubebuilder:rbac:groups="",namespace="updateservice-operator",resources=pods,verbs=get
// +kubebuilder:rbac:groups="apps",namespace="updateservice-operator",resources=replicasets;deployments,verbs=get
// +kubebuilder:rbac:groups="policy",namespace="updateservice-operator",resources=poddisruptionbudgets,verbs=create;delete;get;list;patch;update;watch
// +kubebuilder:rbac:groups=updateservice.operator.openshift.io,namespace="updateservice-operator",resources=*,verbs=create;delete;get;list;patch;update;watch
// +kubebuilder:rbac:groups=config.openshift.io,resources=images,verbs=get;list;watch
// +kubebuilder:rbac:groups=route.openshift.io,resources=routes,verbs=create;get;list;patch;update;watch
// +kubebuilder:rbac:groups="",resources=pods,verbs=get
// +kubebuilder:rbac:groups="",resources=pods;services;services/finalizers;endpoints;persistentvolumeclaims;events;configmaps;secrets,verbs=create;delete;get;list;patch;update;watch
// +kubebuilder:rbac:groups="apps",resourceNames=updateservice-operator,resources=deployments/finalizers,verbs=update
// +kubebuilder:rbac:groups="apps",resources=deployments;daemonsets;replicasets;statefulsets,verbs=create;delete;get;list;patch;update;watch
// +kubebuilder:rbac:groups="apps",resources=replicasets;deployments,verbs=get
// +kubebuilder:rbac:groups="",resources=pods,verbs=get
// +kubebuilder:rbac:groups="monitoring.coreos.com",resources=servicemonitors,verbs=create;get
// +kubebuilder:rbac:groups="apps",resourceNames=updateservice-operator,resources=deployments/finalizers,verbs=update
// +kubebuilder:rbac:groups="policy",resources=poddisruptionbudgets,verbs=create;delete;get;list;patch;update;watch
// +kubebuilder:rbac:groups=config.openshift.io,resources=images,verbs=get;list;watch
// +kubebuilder:rbac:groups=route.openshift.io,resources=routes,verbs=create;get;list;patch;update;watch
// +kubebuilder:rbac:groups=updateservice.operator.openshift.io,resources=*,verbs=create;delete;get;list;patch;update;watch

func (r *UpdateServiceReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
Expand Down Expand Up @@ -575,6 +568,12 @@ func (r *UpdateServiceReconciler) ensurePolicyEngineRoute(ctx context.Context, r
return err
}

if uri, _, err := routeapihelpers.IngressURI(found, ""); err == nil {
instance.Status.PolicyEngineURI = uri.String()
} else {
handleErr(reqLogger, &instance.Status, "RouteIngressFailed", err)
}

updated := found.DeepCopy()
// Keep found tls for later use
tls := updated.Spec.TLS
Expand Down
6 changes: 2 additions & 4 deletions controllers/updateservice_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ const (
testUpdateServiceAPIVersion = "testAPIVersion"
testOperandImage = "testOperandImage"
testReplicas = 1
testRegistry = "testRegistry"
testRepository = "testRepository"
testReleases = "testRegistry/testRepository"
testGraphDataImage = "testGraphDataImage"
testConfigMap = "testConfigMap"
)
Expand Down Expand Up @@ -595,8 +594,7 @@ func newDefaultUpdateService() *cv1.UpdateService {
},
Spec: cv1.UpdateServiceSpec{
Replicas: testReplicas,
Registry: testRegistry,
Repository: testRepository,
Releases: testReleases,
GraphDataImage: testGraphDataImage,
},
}
Expand Down
Loading