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

[controller] Fix internal hook and reduce image size #87

Merged
merged 3 commits into from
Aug 22, 2024
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
2 changes: 1 addition & 1 deletion .werf/bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
---
image: bundle
from: registry.deckhouse.io/base_images/scratch@sha256:b054705fcc9f2205777d80a558d920c0b4209efdc3163c22b5bfcb5dda1db5fc
fromCacheVersion: "2024-03-27.1"
fromCacheVersion: 20240821092325
import:
# Rendering .werf/images-digests.yaml is required!
- image: images-digests
Expand Down
2 changes: 1 addition & 1 deletion .werf/python-deps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
---
image: python-dependencies
from: registry.deckhouse.io/base_images/alpine:3.16.3
fromCacheVersion: 2024-02-12
fromCacheVersion: 20240821092325
git:
- add: /
to: /
Expand Down
23 changes: 1 addition & 22 deletions hooks/lib/module/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,4 @@ def get_https_mode(module_name: str, values: dict) -> str:
raise Exception("https mode is not defined")

def get_module_name() -> str:
module = ""
file_path = os.path.abspath(__file__)
external_modules_dir = os.getenv("EXTERNAL_MODULES_DIR")
for dir in os.getenv("MODULES_DIR").split(":"):
if dir.startswith(external_modules_dir):
dir = external_modules_dir
if file_path.startswith(dir):
module = re.sub(f"{dir}/?\d?\d?\d?-?", "", file_path, 1).split("/")[0]
# /deckhouse/external-modules/virtualization/mr/hooks/hook_name.py
# {-------------------------- file_path --------------------------}
# {------ MODULES_DIR ------}{---------- regexp result ----------}}
# virtualization/mr/hooks/hook_name.py
# {-module-name-}{---------------------}
# or
# /deckhouse/modules/900-virtualization/hooks/hook_name.py
# {---------------------- file_path ----------------------}
# {-- MODULES_DIR --}{---{-------- regexp result --------}}
# virtualization/hooks/hook_name.py
# {-module-name-}{-----------------}

break
return module
return "sds-node-configurator"
114 changes: 114 additions & 0 deletions images/sds-health-watcher-controller/src/api/module_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
Copyright 2023 Flant JSC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)

var (
// ModuleConfigGVR GroupVersionResource
ModuleConfigGVR = schema.GroupVersionResource{
Group: SchemeGroupVersion.Group,
Version: SchemeGroupVersion.Version,
Resource: "moduleconfigs",
}
ModuleConfigGVK = schema.GroupVersionKind{
Group: SchemeGroupVersion.Group,
Version: SchemeGroupVersion.Version,
Kind: "ModuleConfig",
}
)

var _ runtime.Object = (*ModuleConfig)(nil)

// +genclient
// +genclient:nonNamespaced
// +k8s:deepcopy-gen=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// ModuleConfig is a configuration for module or for global config values.
type ModuleConfig struct {
metav1.TypeMeta `json:",inline"`
// Standard object's metadata.
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
// +optional
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec ModuleConfigSpec `json:"spec"`

Status ModuleConfigStatus `json:"status,omitempty"`
}

// SettingsValues empty interface in needed to handle DeepCopy generation. DeepCopy does not work with unnamed empty interfaces
type SettingsValues map[string]interface{}

func (v *SettingsValues) DeepCopy() *SettingsValues {
nmap := make(map[string]interface{}, len(*v))

for key, value := range *v {
nmap[key] = value
}

vv := SettingsValues(nmap)

return &vv
}

func (v SettingsValues) DeepCopyInto(out *SettingsValues) {
{
v := &v
clone := v.DeepCopy()
*out = *clone
return
}
}

type ModuleConfigSpec struct {
Version int `json:"version,omitempty"`
Settings SettingsValues `json:"settings,omitempty"`
Enabled *bool `json:"enabled,omitempty"`
}

type ModuleConfigStatus struct {
Version string `json:"version"`
Message string `json:"message"`
}

// +k8s:deepcopy-gen=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// ModuleConfigList is a list of ModuleConfig resources
type ModuleConfigList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`

Items []ModuleConfig `json:"items"`
}

type moduleConfigKind struct{}

func (in *ModuleConfigStatus) GetObjectKind() schema.ObjectKind {
return &moduleConfigKind{}
}

func (f *moduleConfigKind) SetGroupVersionKind(_ schema.GroupVersionKind) {}
func (f *moduleConfigKind) GroupVersionKind() schema.GroupVersionKind {
return ModuleConfigGVK
}
54 changes: 54 additions & 0 deletions images/sds-health-watcher-controller/src/api/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright 2021 Flant JSC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)

// SchemeGroupVersion is group version used to register these objects
var SchemeGroupVersion = schema.GroupVersion{Group: "deckhouse.io", Version: "v1alpha1"}

// Resource takes an unqualified resource and returns a Group qualified GroupResource
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}

var (
// localSchemeBuilder and AddToScheme will stay in k8s.io/kubernetes.
SchemeBuilder runtime.SchemeBuilder
localSchemeBuilder = &SchemeBuilder
AddToScheme = localSchemeBuilder.AddToScheme
)

func init() {
// We only register manually written functions here. The registration of the
// generated functions takes place in the generated files. The separation
// makes the code compile even when the generated files are missing.
localSchemeBuilder.Register(addKnownTypes)
}

// Adds the list of known types to api.Scheme.
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&ModuleConfig{},
&ModuleConfigList{},
)

metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
return nil
}
125 changes: 125 additions & 0 deletions images/sds-health-watcher-controller/src/api/zz_generated.deepcopy.go

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

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

Loading
Loading