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

Manage the ignition stub config #1792

Merged
merged 1 commit into from
Jul 10, 2020
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: 2 additions & 0 deletions cmd/machine-config-operator/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func runStartCmd(cmd *cobra.Command, args []string) {
ctrlctx.ClientBuilder.ConfigClientOrDie(componentName),
ctrlctx.OpenShiftKubeAPIServerKubeNamespacedInformerFactory.Core().V1().ConfigMaps(),
etcdInformer,
ctrlctx.KubeMAOSharedInformer.Core().V1().Secrets(),
)

ctrlctx.NamespacedInformerFactory.Start(ctrlctx.Stop)
Expand All @@ -96,6 +97,7 @@ func runStartCmd(cmd *cobra.Command, args []string) {
ctrlctx.ConfigInformerFactory.Start(ctrlctx.Stop)
ctrlctx.OpenShiftKubeAPIServerKubeNamespacedInformerFactory.Start(ctrlctx.Stop)
ctrlctx.OperatorInformerFactory.Start(ctrlctx.Stop)
ctrlctx.KubeMAOSharedInformer.Start(ctrlctx.Stop)
close(ctrlctx.InformersStarted)

go controller.Run(2, ctrlctx.Stop)
Expand Down
5 changes: 3 additions & 2 deletions cmd/machine-config-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"flag"

"github.com/golang/glog"
"github.com/openshift/machine-config-operator/pkg/server"
"github.com/spf13/cobra"
)

Expand All @@ -28,10 +29,10 @@ var (

func init() {
rootCmd.PersistentFlags().AddGoFlagSet(flag.CommandLine)
rootCmd.PersistentFlags().IntVar(&rootOpts.sport, "secure-port", 22623, "secure port to serve ignition configs")
rootCmd.PersistentFlags().IntVar(&rootOpts.sport, "secure-port", server.SecurePort, "secure port to serve ignition configs")
rootCmd.PersistentFlags().StringVar(&rootOpts.cert, "cert", "/etc/ssl/mcs/tls.crt", "cert file for TLS")
rootCmd.PersistentFlags().StringVar(&rootOpts.key, "key", "/etc/ssl/mcs/tls.key", "key file for TLS")
rootCmd.PersistentFlags().IntVar(&rootOpts.isport, "insecure-port", 22624, "insecure port to serve ignition configs")
rootCmd.PersistentFlags().IntVar(&rootOpts.isport, "insecure-port", server.InsecurePort, "insecure port to serve ignition configs")
}

func main() {
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,7 @@ k8s.io/klog v0.3.0/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk=
k8s.io/klog v0.3.3/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk=
k8s.io/klog v1.0.0 h1:Pt+yjF5aB1xDSVbau4VsWe+dQNzA0qv1LlXdC2dF6Q8=
k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I=
k8s.io/kube-aggregator v0.18.0 h1:J+wa9FDQ3SbgyA8wQBNg2m2FMSm+mMQfs2A58500hs0=
k8s.io/kube-aggregator v0.18.0/go.mod h1:ateewQ5QbjMZF/dihEFXwaEwoA4v/mayRvzfmvb6eqI=
k8s.io/kube-openapi v0.0.0-20190228160746-b3a7cee44a30/go.mod h1:BXM9ceUBTj2QnfH2MK1odQs778ajze1RxcmP6S8RVVc=
k8s.io/kube-openapi v0.0.0-20200121204235-bf4fb3bd569c h1:/KUFqjjqAcY4Us6luF5RDNZ16KJtb49HfR3ZHB9qYXM=
Expand Down
9 changes: 9 additions & 0 deletions manifests/userdata_secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: v1
kind: Secret
metadata:
name: {{.Role}}-user-data-managed
namespace: openshift-machine-api
type: Opaque
data:
disableTemplating: "dHJ1ZQo="
userData: {{.PointerConfig}}
4 changes: 4 additions & 0 deletions pkg/controller/common/controller_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type ControllerContext struct {
APIExtInformerFactory apiextinformers.SharedInformerFactory
ConfigInformerFactory configinformers.SharedInformerFactory
OperatorInformerFactory operatorinformers.SharedInformerFactory
KubeMAOSharedInformer informers.SharedInformerFactory

AvailableResources map[schema.GroupVersionResource]bool

Expand Down Expand Up @@ -71,6 +72,8 @@ func CreateControllerContext(cb *clients.Builder, stop <-chan struct{}, targetNa
opt.FieldSelector = fields.OneTermEqualSelector("metadata.name", "kube-apiserver-to-kubelet-client-ca").String()
},
)
// this is needed to listen for changes in MAO user data secrets to re-apply the ones we define in the MCO (since we manage them)
kubeMAOSharedInformer := informers.NewFilteredSharedInformerFactory(kubeClient, resyncPeriod()(), "openshift-machine-api", nil)

// filter out CRDs that do not have the MCO label
assignFilterLabels := func(opts *metav1.ListOptions) {
Expand Down Expand Up @@ -100,5 +103,6 @@ func CreateControllerContext(cb *clients.Builder, stop <-chan struct{}, targetNa
Stop: stop,
InformersStarted: make(chan struct{}),
ResyncPeriod: resyncPeriod(),
KubeMAOSharedInformer: kubeMAOSharedInformer,
}
}
35 changes: 35 additions & 0 deletions pkg/controller/common/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"io/ioutil"
"net/url"
"reflect"
"sort"

Expand All @@ -20,6 +21,7 @@ import (
"github.com/ghodss/yaml"
"github.com/golang/glog"
"github.com/pkg/errors"
"github.com/vincent-petithory/dataurl"
kerr "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -134,6 +136,39 @@ func MergeMachineConfigs(configs []*mcfgv1.MachineConfig, osImageURL string) (*m
}, nil
}

// PointerConfig generates the stub ignition for the machine to boot properly
// NOTE: If you change this, you also need to change the pointer configuration in openshift/installer, see
// https://github.com/openshift/installer/blob/master/pkg/asset/ignition/machine/node.go#L20
func PointerConfig(ignitionHost string, rootCA []byte) (ign2types.Config, error) {
configSourceURL := &url.URL{
Scheme: "https",
Host: ignitionHost,
Path: "/config/{{.Role}}",
}
// we do decoding here as curly brackets are escaped to %7B and breaks golang's templates
ignitionHostTmpl, err := url.QueryUnescape(configSourceURL.String())
if err != nil {
return ign2types.Config{}, err
}
return ign2types.Config{
Ignition: ign2types.Ignition{
Version: ign2types.MaxVersion.String(),
Config: ign2types.IgnitionConfig{
Append: []ign2types.ConfigReference{{
Source: ignitionHostTmpl,
}},
},
Security: ign2types.Security{
TLS: ign2types.TLS{
CertificateAuthorities: []ign2types.CaReference{{
Source: dataurl.EncodeBytes(rootCA),
}},
},
},
},
}, nil
}

// NewIgnConfig returns an empty ignition config with version set as latest version
func NewIgnConfig() ign2types.Config {
return ign2types.Config{
Expand Down
29 changes: 29 additions & 0 deletions pkg/operator/assets/bindata.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
// manifests/ovirt/coredns.yaml
// manifests/ovirt/keepalived.conf.tmpl
// manifests/ovirt/keepalived.yaml
// manifests/userdata_secret.yaml
// manifests/vsphere/coredns-corefile.tmpl
// manifests/vsphere/coredns.yaml
// manifests/vsphere/keepalived.conf.tmpl
Expand Down Expand Up @@ -2299,6 +2300,32 @@ func manifestsOvirtKeepalivedYaml() (*asset, error) {
return a, nil
}

var _manifestsUserdata_secretYaml = []byte(`apiVersion: v1
kind: Secret
metadata:
name: {{.Role}}-user-data-managed
namespace: openshift-machine-api
type: Opaque
data:
disableTemplating: "dHJ1ZQo="
userData: {{.PointerConfig}}
`)

func manifestsUserdata_secretYamlBytes() ([]byte, error) {
return _manifestsUserdata_secretYaml, nil
}

func manifestsUserdata_secretYaml() (*asset, error) {
bytes, err := manifestsUserdata_secretYamlBytes()
if err != nil {
return nil, err
}

info := bindataFileInfo{name: "manifests/userdata_secret.yaml", size: 0, mode: os.FileMode(0), modTime: time.Unix(0, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}

var _manifestsVsphereCorednsCorefileTmpl = []byte(`. {
errors
health :18080
Expand Down Expand Up @@ -2695,6 +2722,7 @@ var _bindata = map[string]func() (*asset, error){
"manifests/ovirt/coredns.yaml": manifestsOvirtCorednsYaml,
"manifests/ovirt/keepalived.conf.tmpl": manifestsOvirtKeepalivedConfTmpl,
"manifests/ovirt/keepalived.yaml": manifestsOvirtKeepalivedYaml,
"manifests/userdata_secret.yaml": manifestsUserdata_secretYaml,
"manifests/vsphere/coredns-corefile.tmpl": manifestsVsphereCorednsCorefileTmpl,
"manifests/vsphere/coredns.yaml": manifestsVsphereCorednsYaml,
"manifests/vsphere/keepalived.conf.tmpl": manifestsVsphereKeepalivedConfTmpl,
Expand Down Expand Up @@ -2793,6 +2821,7 @@ var _bintree = &bintree{nil, map[string]*bintree{
"keepalived.conf.tmpl": &bintree{manifestsOvirtKeepalivedConfTmpl, map[string]*bintree{}},
"keepalived.yaml": &bintree{manifestsOvirtKeepalivedYaml, map[string]*bintree{}},
}},
"userdata_secret.yaml": &bintree{manifestsUserdata_secretYaml, map[string]*bintree{}},
"vsphere": &bintree{nil, map[string]*bintree{
"coredns-corefile.tmpl": &bintree{manifestsVsphereCorednsCorefileTmpl, map[string]*bintree{}},
"coredns.yaml": &bintree{manifestsVsphereCorednsYaml, map[string]*bintree{}},
Expand Down
2 changes: 1 addition & 1 deletion pkg/operator/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func RenderBootstrap(
templatectrl.BaremetalRuntimeCfgKey: imgs.BaremetalRuntimeCfg,
}

config := getRenderConfig("", string(filesData[kubeAPIServerServingCA]), spec, &imgs.RenderConfigImages, infra.Status.APIServerInternalURL)
config := getRenderConfig("", string(filesData[kubeAPIServerServingCA]), spec, &imgs.RenderConfigImages, infra.Status.APIServerInternalURL, nil)

manifests := []manifest{
{
Expand Down
5 changes: 5 additions & 0 deletions pkg/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ type Operator struct {
proxyListerSynced cache.InformerSynced
oseKubeAPIListerSynced cache.InformerSynced
etcdSynced cache.InformerSynced
maoSecretInformerSynced cache.InformerSynced

// queue only ever has one item, but it has nice error handling backoff/retry semantics
queue workqueue.RateLimitingInterface
Expand Down Expand Up @@ -133,6 +134,7 @@ func New(
configClient configclientset.Interface,
oseKubeAPIInformer coreinformersv1.ConfigMapInformer,
etcdInformer operatorv1.EtcdInformer,
maoSecretInformer coreinformersv1.SecretInformer,
) *Operator {
eventBroadcaster := record.NewBroadcaster()
eventBroadcaster.StartLogging(glog.Infof)
Expand Down Expand Up @@ -165,6 +167,7 @@ func New(
mcpInformer.Informer(),
proxyInformer.Informer(),
oseKubeAPIInformer.Informer(),
maoSecretInformer.Informer(),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jerry this is where we use the actual informer adding it to the event handler so we get a resync every time something changes (which calls syncMachineConfigPools)

} {
i.AddEventHandler(optr.eventHandler())
}
Expand All @@ -184,6 +187,7 @@ func New(
optr.oseKubeAPILister = oseKubeAPIInformer.Lister()
optr.oseKubeAPIListerSynced = oseKubeAPIInformer.Informer().HasSynced

optr.maoSecretInformerSynced = maoSecretInformer.Informer().HasSynced
optr.serviceAccountInformerSynced = serviceAccountInfomer.Informer().HasSynced
optr.clusterRoleInformerSynced = clusterRoleInformer.Informer().HasSynced
optr.clusterRoleBindingInformerSynced = clusterRoleBindingInformer.Informer().HasSynced
Expand Down Expand Up @@ -241,6 +245,7 @@ func (optr *Operator) Run(workers int, stopCh <-chan struct{}) {
optr.clusterCmListerSynced,
optr.serviceAccountInformerSynced,
optr.clusterRoleInformerSynced,
optr.maoSecretInformerSynced,
optr.clusterRoleBindingInformerSynced,
optr.networkListerSynced,
optr.proxyListerSynced,
Expand Down
3 changes: 2 additions & 1 deletion pkg/operator/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ type renderConfig struct {
Images *RenderConfigImages
KubeAPIServerServingCA string
Infra configv1.Infrastructure
PointerConfig string
}

func renderAsset(config *renderConfig, path string) ([]byte, error) {
func renderAsset(config interface{}, path string) ([]byte, error) {
objBytes, err := assets.Asset(path)
if err != nil {
return nil, fmt.Errorf("error getting asset %s: %v", path, err)
Expand Down
Loading