Skip to content

Commit

Permalink
Merge pull request #28 from rwsu/remove-git-fields
Browse files Browse the repository at this point in the history
Remove git fields from CRD
  • Loading branch information
openshift-merge-robot authored Apr 30, 2020
2 parents 0f71362 + d7742f7 commit f9599d4
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 124 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ operator-sdk run --local

## Using an init container to load graph data

The Cincinnati graph data can also be [loaded from an init container](docs/graph-data-init-container.md).
The Cincinnati graph data is loaded from an init container. Before deploying
the cincinnati-operator, you will need to [build and push an init container containing the graph data](docs/graph-data-init-container.md).
26 changes: 8 additions & 18 deletions deploy/crds/cincinnati.openshift.io_cincinnatis_crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,15 @@ spec:
spec:
description: CincinnatiSpec defines the desired state of Cincinnati
properties:
branch:
description: Branch is the git branch to use on GitHub for retrieving
additional graph data.
type: string
gitHubOrg:
description: GitHubOrg is the organization to use on GitHub for retrieving
additional graph data.
type: string
gitHubRepo:
description: GitHubRepo is the repository to use on GitHub for retrieving
additional graph data.
certConfigMapKey:
description: CertConfigMapKey refers to the ConfigMap key that holds
a CA cert to the registry Cincinnati will contact to build the upgrade
graph. The name of the ConfigMap holding the key comes from the field
additionalTrustedCA in the image.config.openshift.io API.
type: string
graphDataImage:
description: GraphDataImage is an init container image that contains
the Cincinnati graph data and copies it to /var/lib/cincinnati/graph-data.
If specified, it takes precedence over GitHubOrg and GitHubRepo and
disables retrieval of graph data from GitHub.
description: GraphDataImage is a container image that contains the Cincinnati
graph data. The data is copied to /var/lib/cincinnati/graph-data.
type: string
registry:
description: Registry is the container registry to use, such as "quay.io".
Expand All @@ -63,10 +55,8 @@ spec:
description: Repository is the repository to use in the Registry, such
as "openshift-release-dev/ocp-release"
type: string
certConfigMapKey:
description: CertConfigMapKey refers to the ConfigMap key that holds a CA cert to the registry Cincinnati will contact to build the upgrade graph. The name of the ConfigMap holding the key comes from the field additionalTrustedCA in the image.config.openshift.io API.
type: string
required:
- graphDataImage
- registry
- replicas
- repository
Expand Down
11 changes: 1 addition & 10 deletions deploy/crds/cincinnati.openshift.io_v1alpha1_cincinnati_cr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,4 @@ spec:
registry: "quay.io"
repository: "openshift-release-dev/ocp-release"
certConfigMapKey: ""
# There two ways to specify the source of the Cincinnati graph data.
# The first is through a github repository specified by these three
# parameters.
gitHubOrg: "openshift"
gitHubRepo: "cincinnati-graph-data"
branch: "master"
# The second is through an init container specified by graphDataImage.
# When specified, graphDataImage takes precedence over gitHubOrg,
# gitHubRepo, and branch.
#graphDataImage: "your-registry/your-repo/your-init-container"
graphDataImage: "your-registry/your-repo/your-init-container"
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ metadata:
"name": "cincinnati-instance"
},
"spec": {
"branch": "master",
"gitHubOrg": "openshift",
"gitHubRepo": "cincinnati-graph-data",
"registry": "quay.io",
"replicas": 1,
"repository": "openshift-release-dev/ocp-release",
"certConfigMapKey": "",
"graphDataImage": "quay.io/cincinnati/demo-graph-data:for-testing-only",
}
}
]
Expand Down
14 changes: 6 additions & 8 deletions docs/graph-data-init-container.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ the graph data from the same location.
## Build the graph data init container

An example of how to build an init container can be found in ./dev/Dockerfile.
In the example, the image clones the Cincinnati graph data repository.
In the example, the image takes a tarball of the Cincinnati graph data repository.
When the init container runs, it untars the data to /var/lib/cincinnati/graph-data.

Build and push the image to your own repository.

````
podman build -f ./dev/Dockerfile -t quay.io/rwsu/cincinnati-graph-data-container:latest
Expand All @@ -24,7 +27,8 @@ podman push quay.io/rwsu/cincinnati-graph-data-container:latest
## Configure the operator to use the init container

Edit the Cincinnati CR to include a new parameter graphDataImage.
The value should be set to the location of your init container image.
The value should be set to the location where you pushed your init
container image.

For the example above:
```
Expand All @@ -38,9 +42,3 @@ spec:
repository: "openshift-release-dev/ocp-release"
graphDataImage: "quay.io/rwsu/cincinnati-graph-data-container:latest"
```

The gitHubOrg, gitHubRepo, and branch parameters in the CR are used
to configure the graph builder to fetch the graph data from a
git repository. If those parameters and graphDataImage are both specified,
graphDataImage will take precedence. The init container will be used in
lieu of fetching the data from git.
25 changes: 3 additions & 22 deletions pkg/apis/cincinnati/v1alpha1/cincinnati_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,9 @@ type CincinnatiSpec struct {
// "openshift-release-dev/ocp-release"
Repository string `json:"repository"`

// GitHubOrg is the organization to use on GitHub for retrieving additional
// graph data.
GitHubOrg string `json:"gitHubOrg,omitempty"`

// GitHubRepo is the repository to use on GitHub for retrieving additional
// graph data.
GitHubRepo string `json:"gitHubRepo,omitempty"`

// Branch is the git branch to use on GitHub for retrieving additional graph
// data.
Branch string `json:"branch,omitempty"`

// GraphDataImage is an init container image that contains the
// Cincinnati graph data and copies it to /var/lib/cincinnati/graph-data. If
// specified, it takes precedence over GitHubOrg and GitHubRepo and disables
// retrieval of graph data from GitHub.
GraphDataImage string `json:"graphDataImage,omitempty"`
// GraphDataImage is a container image that contains the Cincinnati graph
// data. The data is copied to /var/lib/cincinnati/graph-data.
GraphDataImage string `json:"graphDataImage"`

// CertConfigMapKey refers to the ConfigMap key that holds a CA cert to the registry
// Cincinnati will contact to build the upgrade graph. The name of the
Expand All @@ -61,11 +47,6 @@ const (
// ConditionReconcileCompleted reports whether all required resources have been created
// in the cluster and reflect the specified state.
ConditionReconcileCompleted conditionsv1.ConditionType = "ReconcileCompleted"

// ConditionConfigurationConflict reports conflicts in the graph data configuration.
// There are two ways to configure the graph data source. If both ways are configured,
// this condition will indicate that.
ConditionConfigurationConflict conditionsv1.ConditionType = "ConfigurationConflict"
)

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down
16 changes: 1 addition & 15 deletions pkg/controller/cincinnati/cincinnati_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,21 +173,7 @@ func (r *ReconcileCincinnati) Reconcile(request reconcile.Request) (reconcile.Re
Message: "",
})
}
if instance.Spec.GraphDataImage != "" && (instance.Spec.GitHubOrg != "" || instance.Spec.GitHubRepo != "" || instance.Spec.Branch != "") {
conditionsv1.SetStatusCondition(&instanceCopy.Status.Conditions, conditionsv1.Condition{
Type: cv1alpha1.ConditionConfigurationConflict,
Status: corev1.ConditionTrue,
Reason: "ConflictFound",
Message: "graphDataImage and gitHubOrg/gitHubRepo/branch should not be configured at the same time. graphDataImage is winning.",
})
} else {
conditionsv1.SetStatusCondition(&instanceCopy.Status.Conditions, conditionsv1.Condition{
Type: cv1alpha1.ConditionConfigurationConflict,
Status: corev1.ConditionFalse,
Reason: "NoConflicts",
Message: "",
})
}

if err := r.client.Status().Update(ctx, instanceCopy); err != nil {
reqLogger.Error(err, "Failed to update Status")
}
Expand Down
41 changes: 6 additions & 35 deletions pkg/controller/cincinnati/cincinnati_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ const (
testReplicas = 1
testRegistry = "testRegistry"
testRepository = "testRepository"
testGitHubOrg = "testGitHubOrg"
testGitHubRepo = "testGitHubRepo"
testGitHubBranch = "testGitHubBranch"
testGraphDataImage = "testGraphDataImage"
testConfigMap = "testConfigMap"
)
Expand Down Expand Up @@ -70,28 +67,6 @@ func TestReconcileComplete(t *testing.T) {
Type: cv1alpha1.ConditionReconcileCompleted,
Status: corev1.ConditionTrue,
},
{
Type: cv1alpha1.ConditionConfigurationConflict,
Status: corev1.ConditionFalse,
},
},
},
{
name: "ReconcileWithGraphDataImage",
cincinnati: func() *cv1alpha1.Cincinnati {
cincinnati := newDefaultCincinnati()
cincinnati.Spec.GraphDataImage = testGraphDataImage
return cincinnati
}(),
expectedConditions: []conditionsv1.Condition{
{
Type: cv1alpha1.ConditionReconcileCompleted,
Status: corev1.ConditionTrue,
},
{
Type: cv1alpha1.ConditionConfigurationConflict,
Status: corev1.ConditionTrue,
},
},
},
}
Expand Down Expand Up @@ -268,10 +243,8 @@ func TestEnsureDeployment(t *testing.T) {
assert.Equal(t, found.Spec.Template.Spec.Containers[1].Name, resources.policyEngineContainer.Name)
assert.Equal(t, found.Spec.Template.Spec.Containers[1].Image, resources.graphBuilderContainer.Image)

if cincinnati.Spec.GraphDataImage != "" {
initContainer := found.Spec.Template.Spec.InitContainers[0]
assert.Equal(t, &initContainer, resources.graphDataInitContainer)
}
initContainer := found.Spec.Template.Spec.InitContainers[0]
assert.Equal(t, &initContainer, resources.graphDataInitContainer)
})
}
}
Expand Down Expand Up @@ -389,12 +362,10 @@ func newDefaultCincinnati() *cv1alpha1.Cincinnati {
Namespace: testNamespace,
},
Spec: cv1alpha1.CincinnatiSpec{
Replicas: testReplicas,
Registry: testRegistry,
Repository: testRepository,
GitHubOrg: testGitHubOrg,
GitHubRepo: testGitHubRepo,
Branch: testGitHubBranch,
Replicas: testReplicas,
Registry: testRegistry,
Repository: testRepository,
GraphDataImage: testGraphDataImage,
},
}
}
Expand Down
12 changes: 0 additions & 12 deletions pkg/controller/cincinnati/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,6 @@ registry = "{{.Registry}}"
repository = "{{.Repository}}"
fetch_concurrency = 16
{{ if not .GraphDataImage }}
[[plugin_settings]]
name = "github-secondary-metadata-scrape"
github_org = "{{.GitHubOrg}}"
github_repo = "{{.GitHubRepo}}"
reference_branch = "{{.Branch}}"
output_directory = "/var/lib/cincinnati/graph-data"
{{ end }}
[[plugin_settings]]
name = "openshift-secondary-metadata-parse"
data_directory = "/var/lib/cincinnati/graph-data"
Expand Down Expand Up @@ -336,9 +327,6 @@ func (k *kubeResources) newDeployment(instance *cv1alpha1.Cincinnati) *appsv1.De
}

func (k *kubeResources) newGraphDataInitContainer(instance *cv1alpha1.Cincinnati) *corev1.Container {
if instance.Spec.GraphDataImage == "" {
return nil
}
return &corev1.Container{
Name: NameInitContainerGraphData,
Image: instance.Spec.GraphDataImage,
Expand Down

0 comments on commit f9599d4

Please sign in to comment.