Skip to content
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

K8s core component validation #116

Merged
merged 14 commits into from
Dec 11, 2024
Merged
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
Loading