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
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ VERSION ?= 0.0.1
bundle \
bundle-build

ARTIFACT_DIR ?= .
SOURCES := $(shell find . -name '*.go' -not -path "*/vendor/*")
GOBUILDFLAGS ?= -i -mod=vendor
GOLDFLAGS ?= -s -w -X github.com/openshift/cincinnati-operator/version.Operator=$(VERSION)
Expand Down Expand Up @@ -53,7 +54,7 @@ deploy:
func-test: deploy
@echo "Running functional test suite"
go clean -testcache
go test -timeout 20m -v ./functests/...
go test -timeout 20m -v ./functests/... || (oc -n openshift-updateservice adm inspect --dest-dir="$(ARTIFACT_DIR)/inspect" namespace/openshift-updateservice customresourcedefinition/updateservices.updateservice.operator.openshift.io updateservice/example; false)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a comment on why the clause is here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's one of two lines touched by f376675 which explains the addition. I'm fine inlining that commit message in a Makefile comment for folks who prefer to not use blame, if folks want. I'm also fine dropping the commit from the pull once I get CI greened up.


unit-test:
@echo "Executing unit tests"
Expand Down
7 changes: 7 additions & 0 deletions api/v1/updateservice_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,14 @@ type UpdateServiceStatus struct {
// engine. Available paths from this URI include:
//
// * /api/upgrades_info/v1/graph, with the update graph recommendations.
// * /api/upgrades_info/graph, with the update graph recommendations, versioned by content-type (e.g. application/vnd.redhat.cincinnati.v1+json).
PolicyEngineURI string `json:"policyEngineURI,optional"`

// metadataURI is the external URI which exposes metadata.
// Available paths from this URI include:
//
// * /api/upgrades_info/signatures/{ALGORITHM}/{DIGEST}/{SIGNATURE}, with release signatures.
MetadataURI string `json:"metadataURI,optional"`
}

// Condition Types
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.4.1
creationTimestamp: null
controller-gen.kubebuilder.io/version: v0.13.0
name: updateservices.updateservice.operator.openshift.io
spec:
group: updateservice.operator.openshift.io
Expand All @@ -31,6 +29,8 @@ spec:
object represents. Servers may infer this from the endpoint the client
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:
type: object
spec:
description: spec is the desired state of the UpdateService service. The
operator will work to ensure that the desired configuration is applied
Expand Down Expand Up @@ -87,20 +87,28 @@ spec:
- type
type: object
type: array
metadataURI:
description: "metadataURI is the external URI which exposes metadata.
Available paths from this URI include: \n * /api/upgrades_info/signatures/{ALGORITHM}/{DIGEST}/{SIGNATURE},
with release signatures."
type: string
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."
with the update graph recommendations. * /api/upgrades_info/graph,
with the update graph recommendations, versioned by content-type
(e.g. application/vnd.redhat.cincinnati.v1+json)."
type: string
required:
- metadataURI
- policyEngineURI
type: object
required:
- metadata
- spec
type: object
additionalPrinterColumns:
- name: Age
- name: Age
description: The age of the UpdateService resource.
type: date
jsonPath: .metadata.creationTimestamp
Expand Down Expand Up @@ -128,9 +136,3 @@ spec:
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
2 changes: 0 additions & 2 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@

---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
creationTimestamp: null
name: updateservice-operator
rules:
- apiGroups:
Expand Down
10 changes: 10 additions & 0 deletions controllers/names.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const (
NameContainerGraphBuilder string = "graph-builder"
// NameContainerPolicyEngine is the Name property of the policy engine container
NameContainerPolicyEngine string = "policy-engine"
// NameContainerMetadata is the Name property of the metadata container
NameContainerMetadata string = "metadata"
// NameInitContainerGraphData is the Name property of the graph data container
NameInitContainerGraphData string = "graph-data"
// OpenshiftConfigNamespace is the name of openshift's configuration namespace
Expand Down Expand Up @@ -48,6 +50,10 @@ func namePolicyEngineService(instance *cv1.UpdateService) string {
return instance.Name + "-policy-engine"
}

func nameMetadataService(instance *cv1.UpdateService) string {
return instance.Name + "-metadata"
}

func nameGraphBuilderService(instance *cv1.UpdateService) string {
return instance.Name + "-graph-builder"
}
Expand All @@ -60,6 +66,10 @@ func oldPolicyEngineRouteName(instance *cv1.UpdateService) string {
return namePolicyEngineService(instance) + "-route"
}

func nameMetadataRoute(instance *cv1.UpdateService) string {
return instance.Name + "-meta-route"
}

func nameAdditionalTrustedCA(instance *cv1.UpdateService) string {
return instance.Name + "-trusted-ca"
}
Expand Down
154 changes: 154 additions & 0 deletions controllers/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,13 @@ type kubeResources struct {
graphBuilderContainer *corev1.Container
graphDataInitContainer *corev1.Container
policyEngineContainer *corev1.Container
metadataContainer *corev1.Container
graphBuilderService *corev1.Service
policyEngineService *corev1.Service
metadataService *corev1.Service
policyEngineRoute *routev1.Route
policyEngineOldRoute *routev1.Route
metadataRoute *routev1.Route
trustedCAConfig *corev1.ConfigMap
trustedClusterCAConfig *corev1.ConfigMap
pullSecret *corev1.Secret
Expand Down Expand Up @@ -123,11 +126,14 @@ func newKubeResources(instance *cv1.UpdateService, image string, pullSecret *cor
k.graphBuilderContainer = k.newGraphBuilderContainer(instance, image)
k.graphDataInitContainer = k.newGraphDataInitContainer(instance)
k.policyEngineContainer = k.newPolicyEngineContainer(instance, image)
k.metadataContainer = k.newMetadataContainer(instance, image)
k.deployment = k.newDeployment(instance)
k.graphBuilderService = k.newGraphBuilderService(instance)
k.policyEngineService = k.newPolicyEngineService(instance)
k.metadataService = k.newMetadataService(instance)
k.policyEngineRoute = k.newPolicyEngineRoute(instance)
k.policyEngineOldRoute = k.oldPolicyEngineRoute(instance)
k.metadataRoute = k.newMetadataRoute(instance)
return &k, nil
}

Expand Down Expand Up @@ -217,6 +223,40 @@ func (k *kubeResources) newPolicyEngineService(instance *cv1.UpdateService) *cor
}
}

func (k *kubeResources) newMetadataService(instance *cv1.UpdateService) *corev1.Service {
name := nameMetadataService(instance)
return &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: instance.Namespace,
Labels: map[string]string{
"app": name,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I would expect the app label to be the same as the route that exposes the service? but I haven't looked too deep in how do we organize OSUS resources 🤷

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newMetadataService is using nameMetadataService for app and its own name. This pattern-matches the existing newPolicyEngineService

newMetadataRoute is using nameMetadataRoute for its own name, and nameDeployment for app. This pattern-matches the existing newPolicyEngineRoute.

There are some existing patterns that don't make sense to me, like why the Services expose the status ports that I'd expect only the kubelet to need access to (and the kubelet gets at the containers without passing through the Service). But I've left that kind of refactoring to follow-up work and just matched existing patterns for this new feature.

},
},
Spec: corev1.ServiceSpec{
Type: corev1.ServiceTypeClusterIP,
Ports: []corev1.ServicePort{
{
Name: "metadata",
Port: 80,
TargetPort: intstr.FromInt(8082),
Protocol: corev1.ProtocolTCP,
},
{
Name: "status-m",
Port: 9082,
TargetPort: intstr.FromInt(9082),
Protocol: corev1.ProtocolTCP,
},
},
Selector: map[string]string{
"deployment": nameDeployment(instance),
},
SessionAffinity: corev1.ServiceAffinityNone,
},
}
}

func (k *kubeResources) newPolicyEngineRoute(instance *cv1.UpdateService) *routev1.Route {
name := namePolicyEngineRoute(instance)
return &routev1.Route{
Expand Down Expand Up @@ -269,6 +309,32 @@ func (k *kubeResources) oldPolicyEngineRoute(instance *cv1.UpdateService) *route
}
}

func (k *kubeResources) newMetadataRoute(instance *cv1.UpdateService) *routev1.Route {
name := nameMetadataRoute(instance)
return &routev1.Route{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: instance.Namespace,
Labels: map[string]string{
"app": nameDeployment(instance),
},
},
Spec: routev1.RouteSpec{
Port: &routev1.RoutePort{
TargetPort: intstr.FromString("metadata"),
},
To: routev1.RouteTargetReference{
Kind: "Service",
Name: nameMetadataService(instance),
},
TLS: &routev1.TLSConfig{
Termination: routev1.TLSTerminationEdge,
InsecureEdgeTerminationPolicy: routev1.InsecureEdgeTerminationPolicyNone,
},
},
}
}

func (k *kubeResources) newEnvConfig(instance *cv1.UpdateService) *corev1.ConfigMap {
return &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -283,6 +349,7 @@ func (k *kubeResources) newEnvConfig(instance *cv1.UpdateService) *corev1.Config
"pe.rust_backtrace": "0",
"pe.status.address": "::",
"pe.upstream": "http://localhost:8080/v1/graph",
"m.rust_backtrace": "0",
},
}
}
Expand Down Expand Up @@ -357,6 +424,7 @@ func (k *kubeResources) newDeployment(instance *cv1.UpdateService) *appsv1.Deplo
Containers: []corev1.Container{
*k.graphBuilderContainer,
*k.policyEngineContainer,
*k.metadataContainer,
},
},
},
Expand Down Expand Up @@ -734,6 +802,92 @@ func (k *kubeResources) newPolicyEngineContainer(instance *cv1.UpdateService, im
}
}

func (k *kubeResources) newMetadataContainer(instance *cv1.UpdateService, image string) *corev1.Container {
envConfigName := nameEnvConfig(instance)
return &corev1.Container{
Name: NameContainerMetadata,
Image: image,
ImagePullPolicy: corev1.PullIfNotPresent,
Command: []string{
"/usr/bin/metadata-helper",
},
Args: []string{
"-vvv",
"--signatures.dir",
"/var/lib/cincinnati/graph-data/signatures",
"--service.address",
"::",
"--service.port",
"8082",
"--service.path_prefix",
"/api/upgrades_info",
"--status.address",
"::",
"--status.port",
"9082",
},
Ports: []corev1.ContainerPort{
{
Name: "metadata",
ContainerPort: 8082,
Protocol: corev1.ProtocolTCP,
},
{
Name: "status-m",
ContainerPort: 9082,
Protocol: corev1.ProtocolTCP,
},
},
Env: []corev1.EnvVar{
newCMEnvVar("RUST_BACKTRACE", "m.rust_backtrace", envConfigName),
},
Resources: corev1.ResourceRequirements{
Limits: corev1.ResourceList{
corev1.ResourceCPU: *resource.NewMilliQuantity(750, resource.DecimalSI),
corev1.ResourceMemory: *resource.NewQuantity(768*1024*1024, resource.BinarySI),
},
Requests: corev1.ResourceList{
corev1.ResourceCPU: *resource.NewMilliQuantity(350, resource.DecimalSI),
corev1.ResourceMemory: *resource.NewQuantity(128*1024*1024, resource.BinarySI),
},
},
LivenessProbe: &corev1.Probe{
FailureThreshold: 3,
SuccessThreshold: 1,
InitialDelaySeconds: 150,
PeriodSeconds: 30,
TimeoutSeconds: 3,
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Path: "/livez",
Port: intstr.FromInt(9082),
Scheme: corev1.URISchemeHTTP,
},
},
},
ReadinessProbe: &corev1.Probe{
FailureThreshold: 3,
SuccessThreshold: 1,
InitialDelaySeconds: 150,
PeriodSeconds: 30,
TimeoutSeconds: 3,
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Path: "/readyz",
Port: intstr.FromInt(9082),
Scheme: corev1.URISchemeHTTP,
},
},
},
VolumeMounts: []corev1.VolumeMount{
{
Name: "cincinnati-graph-data",
MountPath: "/var/lib/cincinnati/graph-data",
},
},
}
}

func newCMEnvVar(name, key, cmName string) corev1.EnvVar {
return corev1.EnvVar{
Name: name,
Expand Down
Loading