Skip to content

Commit

Permalink
K8s core component validation (#116)
Browse files Browse the repository at this point in the history
* Add core component definitions in release manifest

* Align helm chart CRD indentations with kubebuilder generated CRD

* Introduce new release manifest CRD changes

* make generate

* Introduce container comparison logic

* Update variable name to improve reusability

* Add deployment monitoring permissions to reconciler

* Introduce helm release comparison function

* Update function to parse K8s distribution

* Introduce wait mechanism for K8s core components

* Fix typos

* Don't fail on job not found errors

* Check deployment staus conditions

* Fix typos
  • Loading branch information
ipetrov117 authored Dec 11, 2024
1 parent 15fcb10 commit d8ae794
Show file tree
Hide file tree
Showing 15 changed files with 663 additions and 153 deletions.
35 changes: 35 additions & 0 deletions api/v1alpha1/releasemanfest_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,38 @@ func TestSupportedArchitectures(t *testing.T) {
assert.Contains(t, supported, "amd64")
assert.Contains(t, supported, "arm64")
}

func TestConvertContainersSliceToMap(t *testing.T) {
expContainer1 := "foo"
expContainerImage1 := "bar"
expContainer2 := "bar"
expContainerImage2 := "baz"

component := CoreComponent{
Containers: []CoreComponentContainer{
{
Name: expContainer1,
Image: expContainerImage1,
},
{
Name: expContainer2,
Image: expContainerImage2,
},
},
}

m := component.ConvertContainerSliceToMap()
assert.Equal(t, 2, len(m))

v, ok := m[expContainer1]
assert.True(t, ok)
assert.Equal(t, expContainerImage1, v)

v, ok = m[expContainer2]
assert.True(t, ok)
assert.Equal(t, expContainerImage2, v)

component = CoreComponent{}
m = component.ConvertContainerSliceToMap()
assert.Empty(t, m)
}
32 changes: 31 additions & 1 deletion api/v1alpha1/releasemanifest_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,37 @@ type Kubernetes struct {
}

type KubernetesDistribution struct {
Version string `json:"version"`
Version string `json:"version"`
CoreComponents []CoreComponent `json:"coreComponents,omitempty"`
}

// +kubebuilder:validation:Enum=HelmChart;Deployment
type CoreComponentType string

const (
HelmChartType CoreComponentType = "HelmChart"
DeploymentType CoreComponentType = "Deployment"
)

type CoreComponent struct {
Name string `json:"name"`
Version string `json:"version,omitempty"`
Containers []CoreComponentContainer `json:"containers,omitempty"`
Type CoreComponentType `json:"type"`
}

func (c *CoreComponent) ConvertContainerSliceToMap() map[string]string {
containerMap := map[string]string{}
for _, container := range c.Containers {
containerMap[container.Name] = container.Image
}

return containerMap
}

type CoreComponentContainer struct {
Name string `json:"name"`
Image string `json:"image"`
}

type OperatingSystem struct {
Expand Down
48 changes: 45 additions & 3 deletions api/v1alpha1/zz_generated.deepcopy.go

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

6 changes: 3 additions & 3 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ func main() {
var watchNamespaces map[string]cache.Config
if watchNamespace != "" {
watchNamespaces = map[string]cache.Config{
watchNamespace: {},
upgrade.HelmChartNamespace: {},
upgrade.SUCNamespace: {},
watchNamespace: {},
upgrade.KubeSystemNamespace: {},
upgrade.SUCNamespace: {},
}
}

Expand Down
58 changes: 58 additions & 0 deletions config/crd/bases/lifecycle.suse.com_releasemanifests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,71 @@ spec:
properties:
k3s:
properties:
coreComponents:
items:
properties:
containers:
items:
properties:
image:
type: string
name:
type: string
required:
- image
- name
type: object
type: array
name:
type: string
type:
enum:
- HelmChart
- Deployment
type: string
version:
type: string
required:
- name
- type
type: object
type: array
version:
type: string
required:
- version
type: object
rke2:
properties:
coreComponents:
items:
properties:
containers:
items:
properties:
image:
type: string
name:
type: string
required:
- image
- name
type: object
type: array
name:
type: string
type:
enum:
- HelmChart
- Deployment
type: string
version:
type: string
required:
- name
- type
type: object
type: array
version:
type: string
required:
Expand Down
8 changes: 8 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ rules:
- customresourcedefinitions
verbs:
- get
- apiGroups:
- apps
resources:
- deployments
verbs:
- get
- list
- watch
- apiGroups:
- batch
resources:
Expand Down
Loading

0 comments on commit d8ae794

Please sign in to comment.