-
Notifications
You must be signed in to change notification settings - Fork 13
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
ROX-18942 - Add operator configuration in fleetshard-sync #1157
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package operator | ||
|
||
import ( | ||
"fmt" | ||
"github.com/golang/glog" | ||
"github.com/stackrox/acs-fleet-manager/internal/dinosaur/pkg/api/private" | ||
"sigs.k8s.io/yaml" | ||
) | ||
|
||
func parseConfig(content []byte) (OperatorConfigs, error) { | ||
var out OperatorConfigs | ||
err := yaml.Unmarshal(content, &out) | ||
if err != nil { | ||
return OperatorConfigs{}, fmt.Errorf("unmarshalling operator config %w", err) | ||
} | ||
return out, nil | ||
} | ||
|
||
// GetConfig returns the rhacs operator configurations | ||
func GetConfig() OperatorConfigs { | ||
// TODO: Read config from GitOps configuration | ||
glog.Error("Reading RHACS Operator GitOps configuration not implemented yet") | ||
return OperatorConfigs{} | ||
} | ||
|
||
// Validate validates the operator configuration and can be used in different life-cycle stages like runtime and deploy time. | ||
func Validate(configs OperatorConfigs) []error { | ||
var errors []error | ||
manager := ACSOperatorManager{ | ||
// TODO: align config URL with fleetshard-sync default | ||
DefaultBaseCRDURL: "https://raw.githubusercontent.com/stackrox/stackrox/%s/operator/bundle/manifests/", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this duplicated there ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed it and replaced with a constant |
||
} | ||
|
||
// TODO: how to run this locally with the same config as fleet-manager? | ||
manifests, err := manager.RenderChart(configs) | ||
kurlov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if err != nil { | ||
errors = append(errors, fmt.Errorf("could not render operator helm charts, got invalid configuration: %s", err.Error())) | ||
} else if len(manifests) == 0 { | ||
errors = append(errors, fmt.Errorf("operator chart rendering succeed, but no manifests rendered")) | ||
} | ||
|
||
return errors | ||
} | ||
|
||
// CRDConfig represents the crd to be installed in the data-plane cluster. The CRD is downloaded automatically | ||
// from the base URL. It takes a GitRef to resolve a GitHub link to the CRD definition. | ||
type CRDConfig struct { | ||
BaseURL string `json:"baseURL,omitempty"` | ||
GitRef string `json:"gitRef"` | ||
} | ||
|
||
// OperatorConfigs represents all operators and the CRD which should be installed in a data-plane cluster. | ||
type OperatorConfigs struct { | ||
CRD CRDConfig `json:"crd"` | ||
Configs []OperatorConfig `json:"operators"` | ||
} | ||
|
||
// OperatorConfig represents the configuration of an operator. | ||
type OperatorConfig struct { | ||
Image string `json:"image"` | ||
GitRef string `json:"gitRef"` | ||
HelmValues string `json:"helmValues,omitempty"` | ||
} | ||
|
||
// ToAPIResponse transforms the config to an private API response. | ||
func (o OperatorConfigs) ToAPIResponse() private.RhacsOperatorConfigs { | ||
apiConfigs := private.RhacsOperatorConfigs{ | ||
CRD: private.RhacsOperatorConfigsCrd{ | ||
GitRef: o.CRD.GitRef, | ||
BaseURL: o.CRD.BaseURL, | ||
}, | ||
} | ||
|
||
for _, config := range o.Configs { | ||
apiConfigs.RHACSOperatorConfigs = append(apiConfigs.RHACSOperatorConfigs, config.ToAPIResponse()) | ||
} | ||
return apiConfigs | ||
} | ||
|
||
// ToAPIResponse converts the internal OperatorConfig to the openapi generated private.RhacsOperatorConfig type. | ||
func (o OperatorConfig) ToAPIResponse() private.RhacsOperatorConfig { | ||
return private.RhacsOperatorConfig{ | ||
Image: o.Image, | ||
GitRef: o.GitRef, | ||
HelmValues: o.HelmValues, | ||
} | ||
} | ||
|
||
// FromAPIResponse converts an openapi generated model to the internal OperatorConfigs type | ||
func FromAPIResponse(config private.RhacsOperatorConfigs) OperatorConfigs { | ||
var operatorConfigs []OperatorConfig | ||
for _, apiConfig := range config.RHACSOperatorConfigs { | ||
config := OperatorConfig{ | ||
Image: apiConfig.Image, | ||
GitRef: apiConfig.GitRef, | ||
HelmValues: apiConfig.HelmValues, | ||
} | ||
operatorConfigs = append(operatorConfigs, config) | ||
} | ||
|
||
return OperatorConfigs{ | ||
Configs: operatorConfigs, | ||
CRD: CRDConfig{ | ||
GitRef: config.CRD.GitRef, | ||
BaseURL: config.CRD.BaseURL, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package operator | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
) | ||
|
||
func getExampleConfig() []byte { | ||
return []byte(` | ||
crd: | ||
baseURL: https://raw.githubusercontent.com/stackrox/stackrox/%s/operator/bundle/manifests/ | ||
gitRef: 4.1.1 | ||
operators: | ||
- gitRef: 4.1.1 | ||
image: "quay.io/rhacs-eng/stackrox-operator:4.1.1" | ||
helmValues: | | ||
operator: | ||
resources: | ||
requests: | ||
memory: 500Mi | ||
cpu: 50m | ||
`) | ||
} | ||
|
||
func TestGetOperatorConfig(t *testing.T) { | ||
conf, err := parseConfig(getExampleConfig()) | ||
require.NoError(t, err) | ||
assert.Len(t, conf.Configs, 1) | ||
assert.Equal(t, "4.1.1", conf.Configs[0].GitRef) | ||
assert.Equal(t, "quay.io/rhacs-eng/stackrox-operator:4.1.1", conf.Configs[0].Image) | ||
} | ||
|
||
func TestValidate(t *testing.T) { | ||
conf, err := parseConfig(getExampleConfig()) | ||
require.NoError(t, err) | ||
|
||
errors := Validate(conf) | ||
assert.Len(t, errors, 0) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider something like:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the variable and replaced it with a constant. We can overwrite the default via GitOps, there is no need for a config as an env variable, it would be duplicated.